@types/prop-types

Search for an npm package
    "@types/prop-types"

@types/prop-types

module "@types/prop-types" {
export function instanceOf<T>(expectedClass: new (...args: any[]) => T): Requireable<T>
export function oneOf<T>(types: readonly T[]): Requireable<T>
export function oneOfType<T extends Validator<any>>(types: T[]): Requireable<NonNullable<InferType<T>>>
export function arrayOf<T>(type: Validator<T>): Requireable<T[]>
export function objectOf<T>(type: Validator<T>): Requireable<{
[K in keyof any]: T;
}>
export function shape<P extends ValidationMap<any>>(type: P): Requireable<InferProps<P>>
export function exact<P extends ValidationMap<any>>(type: P): Requireable<Required<InferProps<P>>>

Assert that the values match with the type specs. Error messages are memorized and will only be shown once.

more
less

@param — Map of name to a ReactPropType

@param — Runtime values that need to be type-checked

@param — e.g. "prop", "context", "child context"

@param — Name of the component for error messages

@param — 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
export type ReactComponentLike = string | ((props: any, context?: any) => any) | (new (props: any, context?: any) => any)
Referenced by
export interface ReactElementLike {
props: any;
key: string | null;
}
Referenced by
export interface ReactNodeArray extends Iterable<ReactNodeLike> {}
Referenced by
export type ReactNodeLike = ReactElementLike | ReactNodeArray | string | number | boolean | null | undefined
Referenced by
export const nominalTypeHack: unique symbol = ...
export type IsOptional<T> = undefined extends T ? true : false
Referenced by
export type RequiredKeys<V> = {
[K in keyof V]-?: Exclude<V[K], undefined> extends Validator<infer T> ? IsOptional<T> extends true ? never : K : never;
}[keyof V]
Referenced by
export type OptionalKeys<V> = Exclude<keyof V, RequiredKeys<V>>
Referenced by
export type InferPropsInner<V> = {
[K in keyof V]-?: InferType<V[K]>;
}
Referenced by
export interface Validator<T> {
(props: {
[key: string]: any;
}, propName: string, componentName: string, location: string, propFullName: string): Error | null;
[nominalTypeHack]?: {
type: T;
} | undefined;
}
Referenced by
export interface Requireable<T> extends Validator<T | undefined | null> {
isRequired: Validator<NonNullable<T>>;
}
Referenced by
export type ValidationMap<T> = {
[K in keyof T]?: Validator<T[K]>;
}
Referenced by

Like ValidationMap but treats undefined, null and optional properties the same. This type is only added as a migration path in React 19 where this type was removed from React. Runtime and compile time types would mismatch since you could see undefined at runtime when your types don't expect this type.

export type WeakValidationMap<T> = {
[K in keyof T]?: null extends T[K] ? Validator<T[K] | null | undefined> : undefined extends T[K] ? Validator<T[K] | null | undefined> : Validator<T[K]>;
}
export type InferType<V> = V extends Validator<infer T> ? T : any
Referenced by
export type InferProps<V> = InferPropsInner<Pick<V, RequiredKeys<V>>> & Partial<InferPropsInner<Pick<V, OptionalKeys<V>>>>
Referenced by
export const any: Requireable<any> = ...
export const array: Requireable<any[]> = ...
export const bool: Requireable<boolean> = ...
export const func: Requireable<(...args: any[]) => any> = ...
export const number: Requireable<number> = ...
export const object: Requireable<object> = ...
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> = ...
}