1 | import { Key } from '../Any/Key';
|
2 | import { x } from '../Any/x';
|
3 | import { Replace } from '../Union/Replace';
|
4 | /**
|
5 | * Update in `O` the fields of key `K` with `A`.
|
6 | * Use the [[x]] placeholder to get the current field type.
|
7 | * @param O to update
|
8 | * @param K to chose fields
|
9 | * @param A to update with
|
10 | * @returns [[Object]]
|
11 | * @example
|
12 | * ```ts
|
13 | * import {A, O} from 'ts-toolbelt'
|
14 | *
|
15 | * type User = {
|
16 | * info: {
|
17 | * name: string
|
18 | * age: number
|
19 | * payment: {}
|
20 | * }
|
21 | * id: number
|
22 | * }
|
23 | *
|
24 | * type test0 = Update<User, 'id' | 'info', A.x | null>
|
25 | * // {
|
26 | * // info: {
|
27 | * // name: string;
|
28 | * // age: number;
|
29 | * // payment: {};
|
30 | * // } | null;
|
31 | * // id: number | null;
|
32 | * // }
|
33 | * ```
|
34 | */
|
35 | export declare type Update<O extends object, K extends Key, A extends any> = {
|
36 | [P in keyof O]: P extends K ? Replace<A, x, O[P]> : O[P];
|
37 | } & {};
|