1+ import { Get } from 'type-fest' ;
2+
13declare const dotProp : {
24 /**
35 Get the value of the property at the given path.
@@ -23,15 +25,11 @@ declare const dotProp: {
2325 //=> 'unicorn'
2426 ```
2527 */
26- get < T > (
27- object : { [ key : string ] : any } | undefined ,
28- path : string
29- ) : T | undefined ;
30- get < T > (
31- object : { [ key : string ] : any } | undefined ,
32- path : string ,
33- defaultValue : T
34- ) : T ;
28+ get : < ObjectType , PathType extends string , DefaultValue = undefined > (
29+ object : ObjectType ,
30+ path : PathType ,
31+ defaultValue ?: DefaultValue
32+ ) => ObjectType extends Record < string , unknown > ? ( Get < ObjectType , PathType > extends unknown ? DefaultValue : Get < ObjectType , PathType > ) : undefined ; // TODO: When adding array index support (https://github.com/sindresorhus/dot-prop/issues/71) add ` | unknown[]` after `Record<string, unknown>`
3533
3634 /**
3735 Set the property at the given path to the given value.
@@ -59,11 +57,11 @@ declare const dotProp: {
5957 //=> {foo: {bar: 'b', baz: 'x'}}
6058 ```
6159 */
62- set < T extends { [ key : string ] : any } > (
63- object : T ,
60+ set : < ObjectType extends { [ key : string ] : any } > (
61+ object : ObjectType ,
6462 path : string ,
6563 value : unknown
66- ) : T ;
64+ ) => ObjectType ;
6765
6866 /**
6967 Check whether the property at the given path exists.
@@ -79,7 +77,7 @@ declare const dotProp: {
7977 //=> true
8078 ```
8179 */
82- has ( object : { [ key : string ] : any } | undefined , path : string ) : boolean ;
80+ has : ( object : { [ key : string ] : any } | undefined , path : string ) => boolean ;
8381
8482 /**
8583 Delete the property at the given path.
@@ -103,7 +101,7 @@ declare const dotProp: {
103101 //=> {foo: {bar: {y: 'x'}}}
104102 ```
105103 */
106- delete ( object : { [ key : string ] : any } , path : string ) : boolean ;
104+ delete : ( object : { [ key : string ] : any } , path : string ) => boolean ;
107105} ;
108106
109107export = dotProp ;
0 commit comments