From fa6f24ebef9e5e706b68f62bfc4bc77fc269ae5a Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Tue, 25 Sep 2018 13:19:17 -0700 Subject: [PATCH] Decouple react from prop-types. --- types/prop-types/index.d.ts | 63 ++++++++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/types/prop-types/index.d.ts b/types/prop-types/index.d.ts index f6176dd59d..fe521031d9 100644 --- a/types/prop-types/index.d.ts +++ b/types/prop-types/index.d.ts @@ -5,18 +5,46 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.8 -import { ReactNode, ReactElement } from 'react'; +export interface ReactElementLike { + type: string | ((...args: any[]) => ReactElementLike); + props: any; + key: string | number | null; + children?: ReactNodeLike; +} + +export interface ReactNodeArray extends Array {} + +export type ReactNodeLike = + | {} + | ReactElementLike + | ReactNodeArray + | string + | number + | boolean + | null + | undefined; export const nominalTypeHack: unique symbol; -export type IsOptional = undefined | null extends T ? true : undefined extends T ? true : null extends T ? true : false; - -export type RequiredKeys = { [K in keyof V]: V[K] extends Validator ? IsOptional extends true ? never : K : never }[keyof V]; +export type IsOptional = undefined | null extends T + ? true + : undefined extends T ? true : null extends T ? true : false; +export type RequiredKeys = { + [K in keyof V]: V[K] extends Validator + ? IsOptional extends true ? never : K + : never +}[keyof V]; export type OptionalKeys = Exclude>; -export type InferPropsInner = { [K in keyof V]: InferType; }; +export type InferPropsInner = { [K in keyof V]: InferType }; export interface Validator { - (props: object, propName: string, componentName: string, location: string, propFullName: string): Error | null; + ( + props: object, + propName: string, + componentName: string, + location: string, + propFullName: string, + ): Error | null; [nominalTypeHack]?: T; } @@ -27,9 +55,8 @@ export interface Requireable extends Validator { export type ValidationMap = { [K in keyof T]-?: Validator }; export type InferType = V extends Validator ? T : any; -export type InferProps = - & InferPropsInner>> - & Partial>>>; +export type InferProps = InferPropsInner>> & + Partial>>>; export const any: Requireable; export const array: Requireable; @@ -38,14 +65,16 @@ export const func: Requireable<(...args: any[]) => any>; export const number: Requireable; export const object: Requireable; export const string: Requireable; -export const node: Requireable; -export const element: Requireable>; +export const node: Requireable; +export const element: Requireable; export const symbol: Requireable; export function instanceOf(expectedClass: new (...args: any[]) => T): Requireable; export function oneOf(types: T[]): Requireable; -export function oneOfType>(types: T[]): Requireable>>; +export function oneOfType>( + types: T[], +): Requireable>>; export function arrayOf(type: Validator): Requireable; -export function objectOf(type: Validator): Requireable<{ [K in keyof any]: T; }>; +export function objectOf(type: Validator): Requireable<{ [K in keyof any]: T }>; export function shape

>(type: P): Requireable>; export function exact

>(type: P): Requireable>>; @@ -59,4 +88,10 @@ export function exact

>(type: P): Requireable any): void; +export function checkPropTypes( + typeSpecs: any, + values: any, + location: string, + componentName: string, + getStack?: () => any, +): void;