@battis/typescript-tricks 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -14,3 +14,27 @@ export type RequireOnlyOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<
|
|
|
14
14
|
export type RecursivePartial<T> = {
|
|
15
15
|
[P in keyof T]?: T[P] extends (infer U)[] ? RecursivePartial<U>[] : T[P] extends object | undefined ? RecursivePartial<T[P]> : T[P];
|
|
16
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* ```ts
|
|
19
|
+
* type A = {
|
|
20
|
+
* d: number,
|
|
21
|
+
* e: string
|
|
22
|
+
* f: boolean
|
|
23
|
+
* }
|
|
24
|
+
*
|
|
25
|
+
* type B = ReplaceProperty<A, 'e', number[]>;
|
|
26
|
+
* // type B = {
|
|
27
|
+
* // d: number,
|
|
28
|
+
* // e: number[],
|
|
29
|
+
* // f: boolean
|
|
30
|
+
* // }
|
|
31
|
+
* ```
|
|
32
|
+
* @see {@link https://stackoverflow.com/a/51599774 StackOverflow response}
|
|
33
|
+
*/
|
|
34
|
+
export type ReplaceProperty<T, K extends keyof T, TReplace> = Identity<Pick<T, Exclude<keyof T, K>> & {
|
|
35
|
+
[P in K]: TReplace;
|
|
36
|
+
}>;
|
|
37
|
+
type Identity<T> = {
|
|
38
|
+
[P in keyof T]: T[P];
|
|
39
|
+
};
|
|
40
|
+
export {};
|
package/package.json
CHANGED