Skip to content

Commit

Permalink
feat(type): add "Required" type parameter to "PropOptions"
Browse files Browse the repository at this point in the history
  • Loading branch information
liximomo committed Sep 19, 2019
1 parent 56f40ba commit 022b43a
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/component/componentProps.ts
@@ -1,14 +1,14 @@
import { Data } from './component';

export type ComponentPropsOptions<P = Data> = {
[K in keyof P]: Prop<P[K]> | null;
[K in keyof P]: Prop<P[K], true | false> | null;
};

type Prop<T> = PropOptions<T> | PropType<T>;
type Prop<T, Required extends boolean> = PropOptions<T, Required> | PropType<T>;

export interface PropOptions<T = any> {
export interface PropOptions<T = any, Required extends boolean = false> {
type?: PropType<T> | null;
required?: boolean;
required?: Required;
default?: T | null | undefined | (() => T | null | undefined);
validator?(value: any): boolean;
}
Expand All @@ -34,7 +34,7 @@ type InferPropType<T> = T extends null
? any // somehow `ObjectConstructor` when inferred from { (): T } becomes `any`
: T extends ObjectConstructor | { type: ObjectConstructor }
? { [key: string]: any }
: T extends Prop<infer V>
: T extends Prop<infer V, true | false>
? V
: T;

Expand Down

0 comments on commit 022b43a

Please sign in to comment.