[prop-types] Make ValidationMap not require a validator for every member (#31133)

* Make ValidationMap not require a validator for every member of the props interface

* Fix InferProps when there are no required keys
This commit is contained in:
Andrew Branch 2018-12-07 13:47:53 -08:00 committed by John Reilly
parent 4add980baf
commit 78e24e6d88

View File

@ -41,12 +41,12 @@ export interface Requireable<T> extends Validator<T | undefined | null> {
isRequired: Validator<NonNullable<T>>;
}
export type ValidationMap<T> = { [K in keyof T]-?: Validator<T[K]> };
export type ValidationMap<T> = { [K in keyof T]?: Validator<T[K]> };
export type InferType<V> = V extends Validator<infer T> ? T : any;
export type InferProps<V> =
& InferPropsInner<Pick<V, RequiredKeys<V>>>
& Partial<InferPropsInner<Pick<V, OptionalKeys<V>>>>;
& (RequiredKeys<V> extends undefined ? {} : InferPropsInner<Pick<V, RequiredKeys<V>>>)
& (OptionalKeys<V> extends undefined ? {} : Partial<InferPropsInner<Pick<V, OptionalKeys<V>>>>);
export const any: Requireable<any>;
export const array: Requireable<any[]>;