1
- type Primitive = null | undefined | string | number | boolean | symbol | bigint ;
1
+ import type { BuiltIns } from './internal' ;
2
2
3
- export type PartialDeep < T > = T extends Primitive
4
- ? Partial < T >
3
+ export type PartialDeep < T > = T extends BuiltIns
4
+ ? T
5
5
: T extends Map < infer KeyType , infer ValueType >
6
6
? PartialMapDeep < KeyType , ValueType >
7
7
: T extends Set < infer ItemType >
@@ -13,34 +13,29 @@ export type PartialDeep<T> = T extends Primitive
13
13
: T extends ( ...args : any [ ] ) => unknown // eslint-disable-line @typescript-eslint/no-explicit-any
14
14
? T | undefined
15
15
: T extends object
16
- ? PartialObjectDeep < T >
16
+ ? T extends ReadonlyArray < infer ItemType > // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
17
+ ? ItemType [ ] extends T // Test for arrays (non-tuples) specifically
18
+ ? readonly ItemType [ ] extends T // Differentiate readonly and mutable arrays
19
+ ? ReadonlyArray < PartialDeep < ItemType | undefined > >
20
+ : Array < PartialDeep < ItemType | undefined > >
21
+ : PartialObjectDeep < T >
22
+ : PartialObjectDeep < T >
17
23
: unknown ;
18
24
19
- /**
20
- Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
21
- */
22
- interface PartialMapDeep < KeyType , ValueType >
23
- extends Map < PartialDeep < KeyType > , PartialDeep < ValueType > > { }
25
+ type PartialMapDeep < KeyType , ValueType > = { } & Map <
26
+ PartialDeep < KeyType > ,
27
+ PartialDeep < ValueType >
28
+ > ;
24
29
25
- /**
26
- Same as `PartialDeep`, but accepts only `Set`s as inputs. Internal helper for `PartialDeep`.
27
- */
28
- interface PartialSetDeep < T > extends Set < PartialDeep < T > > { }
30
+ type PartialSetDeep < T > = { } & Set < PartialDeep < T > > ;
29
31
30
- /**
31
- Same as `PartialDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `PartialDeep`.
32
- */
33
- interface PartialReadonlyMapDeep < KeyType , ValueType >
34
- extends ReadonlyMap < PartialDeep < KeyType > , PartialDeep < ValueType > > { }
32
+ type PartialReadonlyMapDeep < KeyType , ValueType > = { } & ReadonlyMap <
33
+ PartialDeep < KeyType > ,
34
+ PartialDeep < ValueType >
35
+ > ;
35
36
36
- /**
37
- Same as `PartialDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `PartialDeep`.
38
- */
39
- interface PartialReadonlySetDeep < T > extends ReadonlySet < PartialDeep < T > > { }
37
+ type PartialReadonlySetDeep < T > = { } & ReadonlySet < PartialDeep < T > > ;
40
38
41
- /**
42
- Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`.
43
- */
44
39
type PartialObjectDeep < ObjectType extends object > = {
45
40
[ KeyType in keyof SuppressObjectPrototypeOverrides < ObjectType > ] ?: PartialDeep <
46
41
SuppressObjectPrototypeOverrides < ObjectType > [ KeyType ]
0 commit comments