// @jsx: preserve // @strict: true type Defaultize = & {[K in Extract]?: TProps[K]} & {[K in Exclude]: TProps[K]} & Partial; type InferredPropTypes

= {[K in keyof P]: P[K] extends PropTypeChecker ? PropTypeChecker[typeof checkedType] : {}}; declare const checkedType: unique symbol; interface PropTypeChecker { (props: any, propName: string, componentName: string, location: any, propFullName: string): boolean; isRequired: PropTypeChecker; [checkedType]: TRequired extends true ? U : U | null | undefined; } declare namespace PropTypes { export const number: PropTypeChecker; export const string: PropTypeChecker; export const node: PropTypeChecker; } type ReactNode = string | number | ReactComponent<{}, {}>; declare class ReactComponent { constructor(props: P); props: P & Readonly<{children: ReactNode[]}>; setState(s: Partial): S; render(): ReactNode; } declare namespace JSX { interface Element extends ReactComponent {} interface IntrinsicElements {} type LibraryManagedAttributes = TComponent extends { defaultProps: infer D; propTypes: infer P; } ? Defaultize, D> : TComponent extends { defaultProps: infer D } ? Defaultize : TComponent extends { propTypes: infer P } ? TProps & InferredPropTypes

: TProps; } class Component extends ReactComponent { static propTypes = { foo: PropTypes.number, bar: PropTypes.node, baz: PropTypes.string.isRequired, }; static defaultProps = { foo: 42, } } const a = ; const b = ; // Error, missing required prop bar const c = ; const d = ; // Error, baz not a valid prop const e = ; // bar is nullable/undefinable since it's not marked `isRequired` const f = ; // Error, baz is _not_ nullable/undefinable since it's marked `isRequired` class JustPropTypes extends ReactComponent { static propTypes = { foo: PropTypes.number, bar: PropTypes.node.isRequired, }; } const g = ; const h = ; // error, wrong type const i = ; const j = ; // error, bar is required class JustDefaultProps extends ReactComponent { static defaultProps = { foo: 42, }; } const k = ; const l = ; // error, no prop named bar const m = ; // error, wrong type interface FooProps { foo: string; } class BothWithSpecifiedGeneric extends ReactComponent { static propTypes = { foo: PropTypes.string, bar: PropTypes.node, baz: PropTypes.number.isRequired, }; static defaultProps = { foo: "yo", }; } const n = ; const o = ; // Error, missing required prop bar const p = ; const q = ; // Error, baz not a valid prop const r = ; // bar is nullable/undefinable since it's not marked `isRequired` const s = ; // Error, baz is _not_ nullable/undefinable since it's marked `isRequired` class JustPropTypesWithSpecifiedGeneric extends ReactComponent { static propTypes = { foo: PropTypes.string, bar: PropTypes.node.isRequired, }; } const t = ; const u = ; // error, wrong type const v = ; // generic overrides propTypes required-ness, null isn't valid const w = ; // error, bar is required class JustDefaultPropsWithSpecifiedGeneric extends ReactComponent { static defaultProps = { foo: "no", }; } const x = ; const y = ; // error, no prop named bar const z = ; // error, wrong type const aa = ;