main
Last change
on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
881 bytes
|
Rev | Line | |
---|
[d24f17c] | 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 | } & {};
|
---|
Note:
See
TracBrowser
for help on using the repository browser.