File tree Expand file tree Collapse file tree 3 files changed +26
-3
lines changed
primitives/type-utils/src Expand file tree Collapse file tree 3 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,11 @@ export type Noop = () => void;
1212 * d: (x: number) => string;
1313 * e?: () => void; // optional also can be recognized
1414 * }
15- * type FooFnTypes = FunctionUnion<Foo>; // (() => void) | ((x:number)=>string) | (()=>void)
15+ * type FooFnTypes = {
16+ * c: () => void;
17+ * d: (x: number) => string;
18+ * e?: (() => void) | undefined;
19+ }
1620 */
1721export type OnlyFunctions < T > = {
1822 [ K in keyof T as NonNullable < T [ K ] > extends Fn ? K : never ] : T [ K ] ;
@@ -26,7 +30,7 @@ export type OnlyFunctions<T> = {
2630 * b?: string;
2731 * c(): void;
2832 * d: (x: number) => string;
29- * e?: () => void; // 可选也能识别
33+ * e?: () => void;
3034 * }
3135 * type FooFnKeys = FunctionKeys<Foo>; // 'c' | 'd' | 'e'
3236 */
@@ -42,7 +46,7 @@ export type FunctionKeys<T> = {
4246 * b?: string;
4347 * c(): void;
4448 * d: (x: number) => string;
45- * e?: () => void; // 可选也能识别
49+ * e?: () => void;
4650 * }
4751 * type FooFnTypes = FunctionUnion<Foo>; // (() => void) | ((x:number)=>string) | (()=>void)
4852 */
Original file line number Diff line number Diff line change @@ -2,4 +2,6 @@ export * from './fn';
22
33export * from './form' ;
44
5+ export * from './utility-types' ;
6+
57export * from './utils' ;
Original file line number Diff line number Diff line change 1+ /**
2+ * DeepPartial<T>
3+ * @example
4+ * type User = {
5+ * name: string;
6+ * age: number;
7+ * address: {
8+ * city: string;
9+ * street: string;
10+ * };
11+ * };
12+ * type PartialUser = DeepPartial<User>;
13+ * // => { name?: string; age?: number; address?: { city?: string; street?: string } }
14+ */
15+ export type DeepPartial < T > = {
16+ [ K in keyof T ] ?: T [ K ] extends object ? ( T [ K ] extends ( ...args : any [ ] ) => any ? T [ K ] : DeepPartial < T [ K ] > ) : T [ K ] ;
17+ } ;
You can’t perform that action at this time.
0 commit comments