1
+ import { Get } from 'type-fest' ;
2
+
1
3
declare const dotProp : {
2
4
/**
3
5
Get the value of the property at the given path.
@@ -23,15 +25,11 @@ declare const dotProp: {
23
25
//=> 'unicorn'
24
26
```
25
27
*/
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>`
35
33
36
34
/**
37
35
Set the property at the given path to the given value.
@@ -59,11 +57,11 @@ declare const dotProp: {
59
57
//=> {foo: {bar: 'b', baz: 'x'}}
60
58
```
61
59
*/
62
- set < T extends { [ key : string ] : any } > (
63
- object : T ,
60
+ set : < ObjectType extends { [ key : string ] : any } > (
61
+ object : ObjectType ,
64
62
path : string ,
65
63
value : unknown
66
- ) : T ;
64
+ ) => ObjectType ;
67
65
68
66
/**
69
67
Check whether the property at the given path exists.
@@ -79,7 +77,7 @@ declare const dotProp: {
79
77
//=> true
80
78
```
81
79
*/
82
- has ( object : { [ key : string ] : any } | undefined , path : string ) : boolean ;
80
+ has : ( object : { [ key : string ] : any } | undefined , path : string ) => boolean ;
83
81
84
82
/**
85
83
Delete the property at the given path.
@@ -103,7 +101,7 @@ declare const dotProp: {
103
101
//=> {foo: {bar: {y: 'x'}}}
104
102
```
105
103
*/
106
- delete ( object : { [ key : string ] : any } , path : string ) : boolean ;
104
+ delete : ( object : { [ key : string ] : any } , path : string ) => boolean ;
107
105
} ;
108
106
109
107
export = dotProp ;
0 commit comments