8000 feat(type): add "Required" type parameter to "PropOptions" · aztalbot/vue-function-api@022b43a · GitHub
[go: up one dir, main page]

Skip to content

Commit 022b43a

Browse files
committed
feat(type): add "Required" type parameter to "PropOptions"
1 parent 56f40ba commit 022b43a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/component/componentProps.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { Data } from './component';
22

33
export type ComponentPropsOptions<P = Data> = {
4-
[K in keyof P]: Prop<P[K]> | null;
4+
[K in keyof P]: Prop<P[K], true | false> | null;
55
};
66

7-
type Prop<T> = PropOptions<T> | PropType<T>;
7+
type Prop<T, Required extends boolean> = PropOptions<T, Required> | PropType<T>;
88

9-
export interface PropOptions<T = any> {
9+
export interface PropOptions<T = any, Required extends boolean = false> {
1010
type?: PropType<T> | null;
11-
required?: boolean;
11+
required?: Required;
1212
default?: T | null | undefined | (() => T | null | undefined);
1313
validator?(value: any): boolean;
1414
}
@@ -34,7 +34,7 @@ type InferPropType<T> = T extends null
3434
? any // somehow `ObjectConstructor` when inferred from { (): T } becomes `any`
3535
: T extends ObjectConstructor | { type: ObjectConstructor }
3636
? { [key: string]: any }
37-
: T extends Prop<infer V>
37+
: T extends Prop<infer V, true | false>
3838
? V
3939
: T;
4040

0 commit comments

Comments
 (0)
0