Skip to content

Commit e0f8abf

Browse files
kphrxsindresorhus
andcommitted
TypeScript - Fix return type for undefined defaultValue (#56)
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
1 parent b8b7124 commit e0f8abf

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

index.d.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@ declare const dotProp: {
2121
//=> 'unicorn'
2222
```
2323
*/
24+
get<T>(
25+
object: {[key: string]: any},
26+
path: string
27+
): T | undefined;
2428
get<T>(
2529
object: {[key: string]: any},
2630
path: string,
27-
defaultValue?: T
31+
defaultValue: T
2832
): T;
2933

3034
/**

index.test-d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {expectType} from 'tsd';
22
import dotProp = require('.');
33

44
expectType<unknown>(dotProp.get({foo: {bar: 'unicorn'}}, 'foo.bar'));
5+
expectType<string | undefined>(dotProp.get<string>({foo: {bar: 'unicorn'}}, 'foo.bar'));
56
expectType<unknown>(dotProp.get({foo: {bar: 'a'}}, 'foo.notDefined.deep'));
67
expectType<string>(
78
dotProp.get({foo: {bar: 'a'}}, 'foo.notDefined.deep', 'default value')

0 commit comments

Comments
 (0)