From e0f8abf71164321caf1b20109000b08be506f227 Mon Sep 17 00:00:00 2001 From: kPherox Date: Thu, 13 Jun 2019 00:56:16 +0900 Subject: [PATCH] TypeScript - Fix return type for undefined defaultValue (#56) Co-authored-by: Sindre Sorhus --- index.d.ts | 6 +++++- index.test-d.ts | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 136fd5a..a969854 100644 --- a/index.d.ts +++ b/index.d.ts @@ -21,10 +21,14 @@ declare const dotProp: { //=> 'unicorn' ``` */ + get( + object: {[key: string]: any}, + path: string + ): T | undefined; get( object: {[key: string]: any}, path: string, - defaultValue?: T + defaultValue: T ): T; /** diff --git a/index.test-d.ts b/index.test-d.ts index b0defbd..b20181e 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -2,6 +2,7 @@ import {expectType} from 'tsd'; import dotProp = require('.'); expectType(dotProp.get({foo: {bar: 'unicorn'}}, 'foo.bar')); +expectType(dotProp.get({foo: {bar: 'unicorn'}}, 'foo.bar')); expectType(dotProp.get({foo: {bar: 'a'}}, 'foo.notDefined.deep')); expectType( dotProp.get({foo: {bar: 'a'}}, 'foo.notDefined.deep', 'default value')