1 | import type {RequiredKeysOf} from './required-keys-of';
|
2 | import type {Simplify} from './simplify';
|
3 |
|
4 | type SpreadObject<FirstType extends object, SecondType extends object> = {
|
5 | [Key in keyof FirstType]: Key extends keyof SecondType
|
6 | ? FirstType[Key] | Required<SecondType>[Key]
|
7 | : FirstType[Key];
|
8 | } & Pick<
|
9 | SecondType,
|
10 | RequiredKeysOf<SecondType> | Exclude<keyof SecondType, keyof FirstType>
|
11 | >;
|
12 |
|
13 | type TupleOrArray = readonly [...unknown[]];
|
14 |
|
15 | type SpreadTupleOrArray<
|
16 | FirstType extends TupleOrArray,
|
17 | SecondType extends TupleOrArray,
|
18 | > = Array<FirstType[number] | SecondType[number]>;
|
19 |
|
20 | type Spreadable = object | TupleOrArray;
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | export type Spread<
|
78 | FirstType extends Spreadable,
|
79 | SecondType extends Spreadable,
|
80 | > = FirstType extends TupleOrArray
|
81 | ? SecondType extends TupleOrArray
|
82 | ? SpreadTupleOrArray<FirstType, SecondType>
|
83 | : Simplify<SpreadObject<FirstType, SecondType>>
|
84 | : Simplify<SpreadObject<FirstType, SecondType>>;
|