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 <sindresorhus@gmail.com>
  • 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
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
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.