1 | export type ReactComponentLike =
|
2 | | string
|
3 | | ((props: any, context?: any) => any)
|
4 | | (new(props: any, context?: any) => any);
|
5 |
|
6 | export interface ReactElementLike {
|
7 | type: ReactComponentLike;
|
8 | props: any;
|
9 | key: string | null;
|
10 | }
|
11 |
|
12 | export interface ReactNodeArray extends Iterable<ReactNodeLike> {}
|
13 |
|
14 | export type ReactNodeLike =
|
15 | | ReactElementLike
|
16 | | ReactNodeArray
|
17 | | string
|
18 | | number
|
19 | | boolean
|
20 | | null
|
21 | | undefined;
|
22 |
|
23 | export const nominalTypeHack: unique symbol;
|
24 |
|
25 | export type IsOptional<T> = undefined extends T ? true : false;
|
26 |
|
27 | export type RequiredKeys<V> = {
|
28 | [K in keyof V]-?: Exclude<V[K], undefined> extends Validator<infer T> ? IsOptional<T> extends true ? never : K
|
29 | : never;
|
30 | }[keyof V];
|
31 | export type OptionalKeys<V> = Exclude<keyof V, RequiredKeys<V>>;
|
32 | export type InferPropsInner<V> = { [K in keyof V]-?: InferType<V[K]> };
|
33 |
|
34 | export interface Validator<T> {
|
35 | (
|
36 | props: { [key: string]: any },
|
37 | propName: string,
|
38 | componentName: string,
|
39 | location: string,
|
40 | propFullName: string,
|
41 | ): Error | null;
|
42 | [nominalTypeHack]?: {
|
43 | type: T;
|
44 | } | undefined;
|
45 | }
|
46 |
|
47 | export interface Requireable<T> extends Validator<T | undefined | null> {
|
48 | isRequired: Validator<NonNullable<T>>;
|
49 | }
|
50 |
|
51 | export type ValidationMap<T> = { [K in keyof T]?: Validator<T[K]> };
|
52 |
|
53 | /**
|
54 | * Like {@link ValidationMap} but treats `undefined`, `null` and optional properties the same.
|
55 | * This type is only added as a migration path in React 19 where this type was removed from React.
|
56 | * Runtime and compile time types would mismatch since you could see `undefined` at runtime when your types don't expect this type.
|
57 | */
|
58 | export type WeakValidationMap<T> = {
|
59 | [K in keyof T]?: null extends T[K] ? Validator<T[K] | null | undefined>
|
60 | : undefined extends T[K] ? Validator<T[K] | null | undefined>
|
61 | : Validator<T[K]>;
|
62 | };
|
63 |
|
64 | export type InferType<V> = V extends Validator<infer T> ? T : any;
|
65 | export type InferProps<V> =
|
66 | & InferPropsInner<Pick<V, RequiredKeys<V>>>
|
67 | & Partial<InferPropsInner<Pick<V, OptionalKeys<V>>>>;
|
68 |
|
69 | export const any: Requireable<any>;
|
70 | export const array: Requireable<any[]>;
|
71 | export const bool: Requireable<boolean>;
|
72 | export const func: Requireable<(...args: any[]) => any>;
|
73 | export const number: Requireable<number>;
|
74 | export const object: Requireable<object>;
|
75 | export const string: Requireable<string>;
|
76 | export const node: Requireable<ReactNodeLike>;
|
77 | export const element: Requireable<ReactElementLike>;
|
78 | export const symbol: Requireable<symbol>;
|
79 | export const elementType: Requireable<ReactComponentLike>;
|
80 | export function instanceOf<T>(expectedClass: new(...args: any[]) => T): Requireable<T>;
|
81 | export function oneOf<T>(types: readonly T[]): Requireable<T>;
|
82 | export function oneOfType<T extends Validator<any>>(types: T[]): Requireable<NonNullable<InferType<T>>>;
|
83 | export function arrayOf<T>(type: Validator<T>): Requireable<T[]>;
|
84 | export function objectOf<T>(type: Validator<T>): Requireable<{ [K in keyof any]: T }>;
|
85 | export function shape<P extends ValidationMap<any>>(type: P): Requireable<InferProps<P>>;
|
86 | export function exact<P extends ValidationMap<any>>(type: P): Requireable<Required<InferProps<P>>>;
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 | export function checkPropTypes(
|
99 | typeSpecs: any,
|
100 | values: any,
|
101 | location: string,
|
102 | componentName: string,
|
103 | getStack?: () => any,
|
104 | ): void;
|
105 |
|
106 |
|
107 |
|
108 |
|
109 | export function resetWarningCache(): void;
|