Skip to content

Commit

Permalink
TypeScript - Fix return type for undefined defaultValue (#56)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <[email protected]>
  • Loading branch information
kphrx and sindresorhus committed Jun 12, 2019
1 parent b8b7124 commit e0f8abf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ declare const dotProp: {
//=> 'unicorn'
```
*/
get<T>(
object: {[key: string]: any},
path: string
): T | undefined;
get<T>(
object: {[key: string]: any},
path: string,
defaultValue?: T
defaultValue: T
): T;

/**
Expand Down
1 change: 1 addition & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {expectType} from 'tsd';
import dotProp = require('.');

expectType<unknown>(dotProp.get({foo: {bar: 'unicorn'}}, 'foo.bar'));
expectType<string | undefined>(dotProp.get<string>({foo: {bar: 'unicorn'}}, 'foo.bar'));
expectType<unknown>(dotProp.get({foo: {bar: 'a'}}, 'foo.notDefined.deep'));
expectType<string>(
dotProp.get({foo: {bar: 'a'}}, 'foo.notDefined.deep', 'default value')
Expand Down

0 comments on commit e0f8abf

Please sign in to comment.