-
-
Notifications
You must be signed in to change notification settings - Fork 148
/
Assign.ts
31 lines (29 loc) · 890 Bytes
/
Assign.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import {Iteration} from '../Iteration/Iteration'
import {IterationOf} from '../Iteration/IterationOf'
import {Merge} from './Merge'
import {Pos} from '../Iteration/Pos'
import {Next} from '../Iteration/Next'
import {Length} from '../Tuple/Length'
import {Cast} from '../Any/Cast'
import {Tuple} from '../Tuple/Tuple'
import {Key} from '../Iteration/Key'
type _Assign<O extends object, Os extends Tuple<object>, I extends Iteration = IterationOf<'0'>> = {
0: _Assign<Merge<Os[Pos<I>], O>, Os, Next<I>>
1: O
}[
Pos<I> extends Length<Os>
? 1
: 0
]
/** Assign a list of **`object`** into **`O`** with **`Merge`** (last-in overrides)
* @param O to assign to
* @param Os to assign
* @returns **`object`**
* @example
* ```ts
* ```
*/
export type Assign<O extends object, Os extends Tuple<object>> =
_Assign<O, Os> extends infer X
? Cast<X, object>
: never