Skip to content

Commit

Permalink
[prop-types] add elementType and resetWarningCache
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Feb 26, 2019
1 parent 0e29f17 commit cb1912d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 8 additions & 1 deletion types/prop-types/index.d.ts
@@ -1,7 +1,8 @@
// Type definitions for prop-types 15.5
// Type definitions for prop-types 15.7
// Project: https://github.com/reactjs/prop-types, https://facebook.github.io/react
// Definitions by: DovydasNavickas <https://github.com/DovydasNavickas>
// Ferdy Budhidharma <https://github.com/ferdaber>
// Sebastian Silbermann <https://github.com/eps1lon>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8

Expand Down Expand Up @@ -62,6 +63,7 @@ export const string: Requireable<string>;
export const node: Requireable<ReactNodeLike>;
export const element: Requireable<ReactElementLike>;
export const symbol: Requireable<symbol>;
export const elementType: Requireable<ReactComponentLike>;
export function instanceOf<T>(expectedClass: new (...args: any[]) => T): Requireable<T>;
export function oneOf<T>(types: T[]): Requireable<T>;
export function oneOfType<T extends Validator<any>>(types: T[]): Requireable<NonNullable<InferType<T>>>;
Expand All @@ -81,3 +83,8 @@ export function exact<P extends ValidationMap<any>>(type: P): Requireable<Requir
* @param getStack Returns the component stack.
*/
export function checkPropTypes(typeSpecs: any, values: any, location: string, componentName: string, getStack?: () => any): void;

/**
* Only available if NODE_ENV=production
*/
export function resetWarningCache(): void;
8 changes: 6 additions & 2 deletions types/prop-types/prop-types-tests.ts
Expand Up @@ -34,6 +34,7 @@ interface Props {
};
optionalNumber?: number | null;
customProp?: typeof uniqueType;
component: PropTypes.ReactComponentLike;
}

const innerProps = {
Expand Down Expand Up @@ -74,7 +75,8 @@ const propTypes: PropTypesMap = {
objectOf: PropTypes.objectOf(PropTypes.number.isRequired).isRequired,
shape: PropTypes.shape(innerProps).isRequired,
optionalNumber: PropTypes.number,
customProp: (() => null) as PropTypes.Validator<typeof uniqueType | undefined>
customProp: (() => null) as PropTypes.Validator<typeof uniqueType | undefined>,
component: PropTypes.elementType.isRequired
};

// JS checking
Expand All @@ -100,7 +102,8 @@ const propTypesWithoutAnnotation = {
objectOf: PropTypes.objectOf(PropTypes.number.isRequired).isRequired,
shape: PropTypes.shape(innerProps).isRequired,
optionalNumber: PropTypes.number,
customProp: (() => null) as PropTypes.Validator<typeof uniqueType | undefined>
customProp: (() => null) as PropTypes.Validator<typeof uniqueType | undefined>,
component: PropTypes.elementType.isRequired
};

const partialPropTypes = {
Expand Down Expand Up @@ -150,6 +153,7 @@ type ExtractFromOuterPropsMatch4 = Props extends ExtractedPropsFromOuterPropsWit
type ExtractPropsMismatch = ExtractedPartialProps extends Props ? true : false;

PropTypes.checkPropTypes({ xs: PropTypes.array }, { xs: [] }, 'location', 'componentName');
PropTypes.resetWarningCache();

// This would be the type that JSX sees
type Defaultize<T, D> =
Expand Down

0 comments on commit cb1912d

Please sign in to comment.