diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 763abcf5e0115..f2f8afe2b160c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15870,8 +15870,9 @@ namespace ts { return getUnionType(map(signatures, ctor ? t => getJsxPropsTypeFromClassType(t, isJs, context, /*reportErrors*/ false) : t => getJsxPropsTypeFromCallSignature(t, context)), UnionReduction.None); } - function getJsxPropsTypeFromCallSignature(sig: Signature, context: Node) { + function getJsxPropsTypeFromCallSignature(sig: Signature, context: JsxOpeningLikeElement) { let propsType = getTypeOfFirstParameterOfSignatureWithFallback(sig, emptyObjectType); + propsType = getJsxManagedAttributesFromLocatedAttributes(context, getJsxNamespaceAt(context), propsType); const intrinsicAttribs = getJsxType(JsxNames.IntrinsicAttributes, context); if (intrinsicAttribs !== errorType) { propsType = intersectTypes(intrinsicAttribs, propsType); @@ -15884,9 +15885,26 @@ namespace ts { return isTypeAny(instanceType) ? instanceType : getTypeOfPropertyOfType(instanceType, forcedLookupLocation); } + function getJsxManagedAttributesFromLocatedAttributes(context: JsxOpeningLikeElement, ns: Symbol, attributesType: Type) { + const managedSym = getJsxLibraryManagedAttributes(ns); + if (managedSym) { + const declaredManagedType = getDeclaredTypeOfSymbol(managedSym); + if (length((declaredManagedType as GenericType).typeParameters) >= 2) { + const args = fillMissingTypeArguments([checkExpressionCached(context.tagName), attributesType], (declaredManagedType as GenericType).typeParameters, 2, isInJavaScriptFile(context)); + return createTypeReference((declaredManagedType as GenericType), args); + } + else if (length(declaredManagedType.aliasTypeArguments) >= 2) { + const args = fillMissingTypeArguments([checkExpressionCached(context.tagName), attributesType], declaredManagedType.aliasTypeArguments!, 2, isInJavaScriptFile(context)); + return getTypeAliasInstantiation(declaredManagedType.aliasSymbol!, args); + } + } + return attributesType; + } + function getJsxPropsTypeFromClassType(sig: Signature, isJs: boolean, context: JsxOpeningLikeElement, reportErrors: boolean) { - const forcedLookupLocation = getJsxElementPropertiesName(getJsxNamespaceAt(context)); - const attributesType = forcedLookupLocation === undefined + const ns = getJsxNamespaceAt(context); + const forcedLookupLocation = getJsxElementPropertiesName(ns); + let attributesType = forcedLookupLocation === undefined // If there is no type ElementAttributesProperty, return the type of the first parameter of the signature, which should be the props type ? getTypeOfFirstParameterOfSignatureWithFallback(sig, emptyObjectType) : forcedLookupLocation === "" @@ -15902,7 +15920,10 @@ namespace ts { } return emptyObjectType; } - else if (isTypeAny(attributesType)) { + + attributesType = getJsxManagedAttributesFromLocatedAttributes(context, ns, attributesType); + + if (isTypeAny(attributesType)) { // Props is of type 'any' or unknown return attributesType; } @@ -16733,6 +16754,11 @@ namespace ts { return undefined; } + function getJsxLibraryManagedAttributes(jsxNamespace: Symbol) { + // JSX.LibraryManagedAttributes [symbol] + return jsxNamespace && getSymbol(jsxNamespace.exports!, JsxNames.LibraryManagedAttributes, SymbolFlags.Type); + } + /// e.g. "props" for React.d.ts, /// or 'undefined' if ElementAttributesProperty doesn't exist (which means all /// non-intrinsic elements' attributes type is 'any'), @@ -29067,6 +29093,7 @@ namespace ts { export const Element = "Element" as __String; export const IntrinsicAttributes = "IntrinsicAttributes" as __String; export const IntrinsicClassAttributes = "IntrinsicClassAttributes" as __String; + export const LibraryManagedAttributes = "LibraryManagedAttributes" as __String; // tslint:enable variable-name } } diff --git a/tests/baselines/reference/tsxLibraryManagedAttributes.errors.txt b/tests/baselines/reference/tsxLibraryManagedAttributes.errors.txt new file mode 100644 index 0000000000000..d221273116460 --- /dev/null +++ b/tests/baselines/reference/tsxLibraryManagedAttributes.errors.txt @@ -0,0 +1,199 @@ +tests/cases/conformance/jsx/tsxLibraryManagedAttributes.tsx(55,12): error TS2322: Type '{ foo: number; }' is not assignable to type 'Defaultize; bar: PropTypeChecker; baz: PropTypeChecker; }>, { foo: number; }>'. + Type '{ foo: number; }' is not assignable to type '{ bar: string | number | ReactComponent<{}, {}> | null | undefined; baz: string; }'. + Property 'bar' is missing in type '{ foo: number; }'. +tests/cases/conformance/jsx/tsxLibraryManagedAttributes.tsx(57,41): error TS2339: Property 'bat' does not exist on type 'Defaultize; bar: PropTypeChecker; baz: PropTypeChecker; }>, { foo: number; }>'. +tests/cases/conformance/jsx/tsxLibraryManagedAttributes.tsx(59,42): error TS2326: Types of property 'baz' are incompatible. + Type 'null' is not assignable to type 'string'. +tests/cases/conformance/jsx/tsxLibraryManagedAttributes.tsx(69,26): error TS2326: Types of property 'foo' are incompatible. + Type 'string' is not assignable to type 'number | null | undefined'. +tests/cases/conformance/jsx/tsxLibraryManagedAttributes.tsx(71,35): error TS2326: Types of property 'bar' are incompatible. + Type 'null' is not assignable to type 'ReactNode'. +tests/cases/conformance/jsx/tsxLibraryManagedAttributes.tsx(80,38): error TS2339: Property 'bar' does not exist on type 'Defaultize<{}, { foo: number; }>'. +tests/cases/conformance/jsx/tsxLibraryManagedAttributes.tsx(81,29): error TS2326: Types of property 'foo' are incompatible. + Type 'string' is not assignable to type 'number | undefined'. +tests/cases/conformance/jsx/tsxLibraryManagedAttributes.tsx(98,12): error TS2322: Type '{ foo: string; }' is not assignable to type 'Defaultize; bar: PropTypeChecker; baz: PropTypeChecker; }>, { foo: string; }>'. + Type '{ foo: string; }' is not assignable to type '{ bar: string | number | ReactComponent<{}, {}> | null | undefined; baz: number; }'. + Property 'bar' is missing in type '{ foo: string; }'. +tests/cases/conformance/jsx/tsxLibraryManagedAttributes.tsx(100,56): error TS2339: Property 'bat' does not exist on type 'Defaultize; bar: PropTypeChecker; baz: PropTypeChecker; }>, { foo: string; }>'. +tests/cases/conformance/jsx/tsxLibraryManagedAttributes.tsx(102,57): error TS2326: Types of property 'baz' are incompatible. + Type 'null' is not assignable to type 'number'. +tests/cases/conformance/jsx/tsxLibraryManagedAttributes.tsx(111,46): error TS2326: Types of property 'foo' are incompatible. + Type 'number' is not assignable to type 'string'. +tests/cases/conformance/jsx/tsxLibraryManagedAttributes.tsx(112,46): error TS2326: Types of property 'foo' are incompatible. + Type 'null' is not assignable to type 'string'. +tests/cases/conformance/jsx/tsxLibraryManagedAttributes.tsx(113,57): error TS2326: Types of property 'bar' are incompatible. + Type 'null' is not assignable to type 'ReactNode'. +tests/cases/conformance/jsx/tsxLibraryManagedAttributes.tsx(122,58): error TS2339: Property 'bar' does not exist on type 'Defaultize'. +tests/cases/conformance/jsx/tsxLibraryManagedAttributes.tsx(123,49): error TS2326: Types of property 'foo' are incompatible. + Type 'number' is not assignable to type 'string | undefined'. + + +==== tests/cases/conformance/jsx/tsxLibraryManagedAttributes.tsx (15 errors) ==== + 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 + ~~~~~~~~~ +!!! error TS2322: Type '{ foo: number; }' is not assignable to type 'Defaultize; bar: PropTypeChecker; baz: PropTypeChecker; }>, { foo: number; }>'. +!!! error TS2322: Type '{ foo: number; }' is not assignable to type '{ bar: string | number | ReactComponent<{}, {}> | null | undefined; baz: string; }'. +!!! error TS2322: Property 'bar' is missing in type '{ foo: number; }'. + const c = ; + const d = ; // Error, baz not a valid prop + ~~~~~~~~~~ +!!! error TS2339: Property 'bat' does not exist on type 'Defaultize; bar: PropTypeChecker; baz: PropTypeChecker; }>, { foo: number; }>'. + 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` + ~~~~~~~~~~ +!!! error TS2326: Types of property 'baz' are incompatible. +!!! error TS2326: Type 'null' is not assignable to type 'string'. + + class JustPropTypes extends ReactComponent { + static propTypes = { + foo: PropTypes.number, + bar: PropTypes.node.isRequired, + }; + } + + const g = ; + const h = ; // error, wrong type + ~~~~~~~~ +!!! error TS2326: Types of property 'foo' are incompatible. +!!! error TS2326: Type 'string' is not assignable to type 'number | null | undefined'. + const i = ; + const j = ; // error, bar is required + ~~~~~~~~~~ +!!! error TS2326: Types of property 'bar' are incompatible. +!!! error TS2326: Type 'null' is not assignable to type 'ReactNode'. + + class JustDefaultProps extends ReactComponent { + static defaultProps = { + foo: 42, + }; + } + + const k = ; + const l = ; // error, no prop named bar + ~~~~~~~~ +!!! error TS2339: Property 'bar' does not exist on type 'Defaultize<{}, { foo: number; }>'. + const m = ; // error, wrong type + ~~~~~~~~ +!!! error TS2326: Types of property 'foo' are incompatible. +!!! error TS2326: Type 'string' is not assignable to type 'number | undefined'. + + 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 + ~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '{ foo: string; }' is not assignable to type 'Defaultize; bar: PropTypeChecker; baz: PropTypeChecker; }>, { foo: string; }>'. +!!! error TS2322: Type '{ foo: string; }' is not assignable to type '{ bar: string | number | ReactComponent<{}, {}> | null | undefined; baz: number; }'. +!!! error TS2322: Property 'bar' is missing in type '{ foo: string; }'. + const p = ; + const q = ; // Error, baz not a valid prop + ~~~~~~~~~~ +!!! error TS2339: Property 'bat' does not exist on type 'Defaultize; bar: PropTypeChecker; baz: PropTypeChecker; }>, { foo: string; }>'. + 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` + ~~~~~~~~~~ +!!! error TS2326: Types of property 'baz' are incompatible. +!!! error TS2326: Type 'null' is not assignable to type 'number'. + + class JustPropTypesWithSpecifiedGeneric extends ReactComponent { + static propTypes = { + foo: PropTypes.string, + bar: PropTypes.node.isRequired, + }; + } + const t = ; + const u = ; // error, wrong type + ~~~~~~~~ +!!! error TS2326: Types of property 'foo' are incompatible. +!!! error TS2326: Type 'number' is not assignable to type 'string'. + const v = ; // generic overrides propTypes required-ness, null isn't valid + ~~~~~~~~~~ +!!! error TS2326: Types of property 'foo' are incompatible. +!!! error TS2326: Type 'null' is not assignable to type 'string'. + const w = ; // error, bar is required + ~~~~~~~~~~ +!!! error TS2326: Types of property 'bar' are incompatible. +!!! error TS2326: Type 'null' is not assignable to type 'ReactNode'. + + class JustDefaultPropsWithSpecifiedGeneric extends ReactComponent { + static defaultProps = { + foo: "no", + }; + } + + const x = ; + const y = ; // error, no prop named bar + ~~~~~~~~ +!!! error TS2339: Property 'bar' does not exist on type 'Defaultize'. + const z = ; // error, wrong type + ~~~~~~~~ +!!! error TS2326: Types of property 'foo' are incompatible. +!!! error TS2326: Type 'number' is not assignable to type 'string | undefined'. + const aa = ; + \ No newline at end of file diff --git a/tests/baselines/reference/tsxLibraryManagedAttributes.js b/tests/baselines/reference/tsxLibraryManagedAttributes.js new file mode 100644 index 0000000000000..bbc12bcecbb1d --- /dev/null +++ b/tests/baselines/reference/tsxLibraryManagedAttributes.js @@ -0,0 +1,241 @@ +//// [tsxLibraryManagedAttributes.tsx] +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 = ; + + +//// [tsxLibraryManagedAttributes.jsx] +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + } + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var Component = /** @class */ (function (_super) { + __extends(Component, _super); + function Component() { + return _super !== null && _super.apply(this, arguments) || this; + } + Component.propTypes = { + foo: PropTypes.number, + bar: PropTypes.node, + baz: PropTypes.string.isRequired + }; + Component.defaultProps = { + foo: 42 + }; + return Component; +}(ReactComponent)); +var a = ; +var b = ; // Error, missing required prop bar +var c = ; +var d = ; // Error, baz not a valid prop +var e = ; // bar is nullable/undefinable since it's not marked `isRequired` +var f = ; // Error, baz is _not_ nullable/undefinable since it's marked `isRequired` +var JustPropTypes = /** @class */ (function (_super) { + __extends(JustPropTypes, _super); + function JustPropTypes() { + return _super !== null && _super.apply(this, arguments) || this; + } + JustPropTypes.propTypes = { + foo: PropTypes.number, + bar: PropTypes.node.isRequired + }; + return JustPropTypes; +}(ReactComponent)); +var g = ; +var h = ; // error, wrong type +var i = ; +var j = ; // error, bar is required +var JustDefaultProps = /** @class */ (function (_super) { + __extends(JustDefaultProps, _super); + function JustDefaultProps() { + return _super !== null && _super.apply(this, arguments) || this; + } + JustDefaultProps.defaultProps = { + foo: 42 + }; + return JustDefaultProps; +}(ReactComponent)); +var k = ; +var l = ; // error, no prop named bar +var m = ; // error, wrong type +var BothWithSpecifiedGeneric = /** @class */ (function (_super) { + __extends(BothWithSpecifiedGeneric, _super); + function BothWithSpecifiedGeneric() { + return _super !== null && _super.apply(this, arguments) || this; + } + BothWithSpecifiedGeneric.propTypes = { + foo: PropTypes.string, + bar: PropTypes.node, + baz: PropTypes.number.isRequired + }; + BothWithSpecifiedGeneric.defaultProps = { + foo: "yo" + }; + return BothWithSpecifiedGeneric; +}(ReactComponent)); +var n = ; +var o = ; // Error, missing required prop bar +var p = ; +var q = ; // Error, baz not a valid prop +var r = ; // bar is nullable/undefinable since it's not marked `isRequired` +var s = ; // Error, baz is _not_ nullable/undefinable since it's marked `isRequired` +var JustPropTypesWithSpecifiedGeneric = /** @class */ (function (_super) { + __extends(JustPropTypesWithSpecifiedGeneric, _super); + function JustPropTypesWithSpecifiedGeneric() { + return _super !== null && _super.apply(this, arguments) || this; + } + JustPropTypesWithSpecifiedGeneric.propTypes = { + foo: PropTypes.string, + bar: PropTypes.node.isRequired + }; + return JustPropTypesWithSpecifiedGeneric; +}(ReactComponent)); +var t = ; +var u = ; // error, wrong type +var v = ; // generic overrides propTypes required-ness, null isn't valid +var w = ; // error, bar is required +var JustDefaultPropsWithSpecifiedGeneric = /** @class */ (function (_super) { + __extends(JustDefaultPropsWithSpecifiedGeneric, _super); + function JustDefaultPropsWithSpecifiedGeneric() { + return _super !== null && _super.apply(this, arguments) || this; + } + JustDefaultPropsWithSpecifiedGeneric.defaultProps = { + foo: "no" + }; + return JustDefaultPropsWithSpecifiedGeneric; +}(ReactComponent)); +var x = ; +var y = ; // error, no prop named bar +var z = ; // error, wrong type +var aa = ; diff --git a/tests/baselines/reference/tsxLibraryManagedAttributes.symbols b/tests/baselines/reference/tsxLibraryManagedAttributes.symbols new file mode 100644 index 0000000000000..c14b2e343a2c4 --- /dev/null +++ b/tests/baselines/reference/tsxLibraryManagedAttributes.symbols @@ -0,0 +1,486 @@ +=== tests/cases/conformance/jsx/tsxLibraryManagedAttributes.tsx === +type Defaultize = +>Defaultize : Symbol(Defaultize, Decl(tsxLibraryManagedAttributes.tsx, 0, 0)) +>TProps : Symbol(TProps, Decl(tsxLibraryManagedAttributes.tsx, 0, 16)) +>TDefaults : Symbol(TDefaults, Decl(tsxLibraryManagedAttributes.tsx, 0, 23)) + + & {[K in Extract]?: TProps[K]} +>K : Symbol(K, Decl(tsxLibraryManagedAttributes.tsx, 1, 8)) +>Extract : Symbol(Extract, Decl(lib.es5.d.ts, --, --)) +>TProps : Symbol(TProps, Decl(tsxLibraryManagedAttributes.tsx, 0, 16)) +>TDefaults : Symbol(TDefaults, Decl(tsxLibraryManagedAttributes.tsx, 0, 23)) +>TProps : Symbol(TProps, Decl(tsxLibraryManagedAttributes.tsx, 0, 16)) +>K : Symbol(K, Decl(tsxLibraryManagedAttributes.tsx, 1, 8)) + + & {[K in Exclude]: TProps[K]} +>K : Symbol(K, Decl(tsxLibraryManagedAttributes.tsx, 2, 8)) +>Exclude : Symbol(Exclude, Decl(lib.es5.d.ts, --, --)) +>TProps : Symbol(TProps, Decl(tsxLibraryManagedAttributes.tsx, 0, 16)) +>TDefaults : Symbol(TDefaults, Decl(tsxLibraryManagedAttributes.tsx, 0, 23)) +>TProps : Symbol(TProps, Decl(tsxLibraryManagedAttributes.tsx, 0, 16)) +>K : Symbol(K, Decl(tsxLibraryManagedAttributes.tsx, 2, 8)) + + & Partial; +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>TDefaults : Symbol(TDefaults, Decl(tsxLibraryManagedAttributes.tsx, 0, 23)) + +type InferredPropTypes

= {[K in keyof P]: P[K] extends PropTypeChecker ? PropTypeChecker[typeof checkedType] : {}}; +>InferredPropTypes : Symbol(InferredPropTypes, Decl(tsxLibraryManagedAttributes.tsx, 3, 25)) +>P : Symbol(P, Decl(tsxLibraryManagedAttributes.tsx, 5, 23)) +>K : Symbol(K, Decl(tsxLibraryManagedAttributes.tsx, 5, 30)) +>P : Symbol(P, Decl(tsxLibraryManagedAttributes.tsx, 5, 23)) +>P : Symbol(P, Decl(tsxLibraryManagedAttributes.tsx, 5, 23)) +>K : Symbol(K, Decl(tsxLibraryManagedAttributes.tsx, 5, 30)) +>PropTypeChecker : Symbol(PropTypeChecker, Decl(tsxLibraryManagedAttributes.tsx, 7, 41)) +>T : Symbol(T, Decl(tsxLibraryManagedAttributes.tsx, 5, 79)) +>U : Symbol(U, Decl(tsxLibraryManagedAttributes.tsx, 5, 88)) +>PropTypeChecker : Symbol(PropTypeChecker, Decl(tsxLibraryManagedAttributes.tsx, 7, 41)) +>T : Symbol(T, Decl(tsxLibraryManagedAttributes.tsx, 5, 79)) +>U : Symbol(U, Decl(tsxLibraryManagedAttributes.tsx, 5, 88)) +>checkedType : Symbol(checkedType, Decl(tsxLibraryManagedAttributes.tsx, 7, 13)) + +declare const checkedType: unique symbol; +>checkedType : Symbol(checkedType, Decl(tsxLibraryManagedAttributes.tsx, 7, 13)) + +interface PropTypeChecker { +>PropTypeChecker : Symbol(PropTypeChecker, Decl(tsxLibraryManagedAttributes.tsx, 7, 41)) +>U : Symbol(U, Decl(tsxLibraryManagedAttributes.tsx, 8, 26)) +>TRequired : Symbol(TRequired, Decl(tsxLibraryManagedAttributes.tsx, 8, 28)) + + (props: any, propName: string, componentName: string, location: any, propFullName: string): boolean; +>props : Symbol(props, Decl(tsxLibraryManagedAttributes.tsx, 9, 5)) +>propName : Symbol(propName, Decl(tsxLibraryManagedAttributes.tsx, 9, 16)) +>componentName : Symbol(componentName, Decl(tsxLibraryManagedAttributes.tsx, 9, 34)) +>location : Symbol(location, Decl(tsxLibraryManagedAttributes.tsx, 9, 57)) +>propFullName : Symbol(propFullName, Decl(tsxLibraryManagedAttributes.tsx, 9, 72)) + + isRequired: PropTypeChecker; +>isRequired : Symbol(PropTypeChecker.isRequired, Decl(tsxLibraryManagedAttributes.tsx, 9, 104)) +>PropTypeChecker : Symbol(PropTypeChecker, Decl(tsxLibraryManagedAttributes.tsx, 7, 41)) +>U : Symbol(U, Decl(tsxLibraryManagedAttributes.tsx, 8, 26)) + + [checkedType]: TRequired extends true ? U : U | null | undefined; +>[checkedType] : Symbol(PropTypeChecker[checkedType], Decl(tsxLibraryManagedAttributes.tsx, 10, 41)) +>checkedType : Symbol(checkedType, Decl(tsxLibraryManagedAttributes.tsx, 7, 13)) +>TRequired : Symbol(TRequired, Decl(tsxLibraryManagedAttributes.tsx, 8, 28)) +>U : Symbol(U, Decl(tsxLibraryManagedAttributes.tsx, 8, 26)) +>U : Symbol(U, Decl(tsxLibraryManagedAttributes.tsx, 8, 26)) +} + +declare namespace PropTypes { +>PropTypes : Symbol(PropTypes, Decl(tsxLibraryManagedAttributes.tsx, 12, 1)) + + export const number: PropTypeChecker; +>number : Symbol(number, Decl(tsxLibraryManagedAttributes.tsx, 15, 16)) +>PropTypeChecker : Symbol(PropTypeChecker, Decl(tsxLibraryManagedAttributes.tsx, 7, 41)) + + export const string: PropTypeChecker; +>string : Symbol(string, Decl(tsxLibraryManagedAttributes.tsx, 16, 16)) +>PropTypeChecker : Symbol(PropTypeChecker, Decl(tsxLibraryManagedAttributes.tsx, 7, 41)) + + export const node: PropTypeChecker; +>node : Symbol(node, Decl(tsxLibraryManagedAttributes.tsx, 17, 16)) +>PropTypeChecker : Symbol(PropTypeChecker, Decl(tsxLibraryManagedAttributes.tsx, 7, 41)) +>ReactNode : Symbol(ReactNode, Decl(tsxLibraryManagedAttributes.tsx, 18, 1)) +} + +type ReactNode = string | number | ReactComponent<{}, {}>; +>ReactNode : Symbol(ReactNode, Decl(tsxLibraryManagedAttributes.tsx, 18, 1)) +>ReactComponent : Symbol(ReactComponent, Decl(tsxLibraryManagedAttributes.tsx, 20, 58)) + +declare class ReactComponent { +>ReactComponent : Symbol(ReactComponent, Decl(tsxLibraryManagedAttributes.tsx, 20, 58)) +>P : Symbol(P, Decl(tsxLibraryManagedAttributes.tsx, 22, 29)) +>S : Symbol(S, Decl(tsxLibraryManagedAttributes.tsx, 22, 34)) + + constructor(props: P); +>props : Symbol(props, Decl(tsxLibraryManagedAttributes.tsx, 23, 16)) +>P : Symbol(P, Decl(tsxLibraryManagedAttributes.tsx, 22, 29)) + + props: P & Readonly<{children: ReactNode[]}>; +>props : Symbol(ReactComponent.props, Decl(tsxLibraryManagedAttributes.tsx, 23, 26)) +>P : Symbol(P, Decl(tsxLibraryManagedAttributes.tsx, 22, 29)) +>Readonly : Symbol(Readonly, Decl(lib.es5.d.ts, --, --)) +>children : Symbol(children, Decl(tsxLibraryManagedAttributes.tsx, 24, 25)) +>ReactNode : Symbol(ReactNode, Decl(tsxLibraryManagedAttributes.tsx, 18, 1)) + + setState(s: Partial): S; +>setState : Symbol(ReactComponent.setState, Decl(tsxLibraryManagedAttributes.tsx, 24, 49)) +>s : Symbol(s, Decl(tsxLibraryManagedAttributes.tsx, 25, 13)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>S : Symbol(S, Decl(tsxLibraryManagedAttributes.tsx, 22, 34)) +>S : Symbol(S, Decl(tsxLibraryManagedAttributes.tsx, 22, 34)) + + render(): ReactNode; +>render : Symbol(ReactComponent.render, Decl(tsxLibraryManagedAttributes.tsx, 25, 31)) +>ReactNode : Symbol(ReactNode, Decl(tsxLibraryManagedAttributes.tsx, 18, 1)) +} + +declare namespace JSX { +>JSX : Symbol(JSX, Decl(tsxLibraryManagedAttributes.tsx, 27, 1)) + + interface Element extends ReactComponent {} +>Element : Symbol(Element, Decl(tsxLibraryManagedAttributes.tsx, 29, 23)) +>ReactComponent : Symbol(ReactComponent, Decl(tsxLibraryManagedAttributes.tsx, 20, 58)) + + interface IntrinsicElements {} +>IntrinsicElements : Symbol(IntrinsicElements, Decl(tsxLibraryManagedAttributes.tsx, 30, 47)) + + type LibraryManagedAttributes = +>LibraryManagedAttributes : Symbol(LibraryManagedAttributes, Decl(tsxLibraryManagedAttributes.tsx, 31, 34)) +>TComponent : Symbol(TComponent, Decl(tsxLibraryManagedAttributes.tsx, 32, 34)) +>TProps : Symbol(TProps, Decl(tsxLibraryManagedAttributes.tsx, 32, 45)) + + TComponent extends { defaultProps: infer D; propTypes: infer P; } +>TComponent : Symbol(TComponent, Decl(tsxLibraryManagedAttributes.tsx, 32, 34)) +>defaultProps : Symbol(defaultProps, Decl(tsxLibraryManagedAttributes.tsx, 33, 28)) +>D : Symbol(D, Decl(tsxLibraryManagedAttributes.tsx, 33, 48)) +>propTypes : Symbol(propTypes, Decl(tsxLibraryManagedAttributes.tsx, 33, 51)) +>P : Symbol(P, Decl(tsxLibraryManagedAttributes.tsx, 33, 68)) + + ? Defaultize, D> +>Defaultize : Symbol(Defaultize, Decl(tsxLibraryManagedAttributes.tsx, 0, 0)) +>TProps : Symbol(TProps, Decl(tsxLibraryManagedAttributes.tsx, 32, 45)) +>InferredPropTypes : Symbol(InferredPropTypes, Decl(tsxLibraryManagedAttributes.tsx, 3, 25)) +>P : Symbol(P, Decl(tsxLibraryManagedAttributes.tsx, 33, 68)) +>D : Symbol(D, Decl(tsxLibraryManagedAttributes.tsx, 33, 48)) + + : TComponent extends { defaultProps: infer D } +>TComponent : Symbol(TComponent, Decl(tsxLibraryManagedAttributes.tsx, 32, 34)) +>defaultProps : Symbol(defaultProps, Decl(tsxLibraryManagedAttributes.tsx, 35, 34)) +>D : Symbol(D, Decl(tsxLibraryManagedAttributes.tsx, 35, 54)) + + ? Defaultize +>Defaultize : Symbol(Defaultize, Decl(tsxLibraryManagedAttributes.tsx, 0, 0)) +>TProps : Symbol(TProps, Decl(tsxLibraryManagedAttributes.tsx, 32, 45)) +>D : Symbol(D, Decl(tsxLibraryManagedAttributes.tsx, 35, 54)) + + : TComponent extends { propTypes: infer P } +>TComponent : Symbol(TComponent, Decl(tsxLibraryManagedAttributes.tsx, 32, 34)) +>propTypes : Symbol(propTypes, Decl(tsxLibraryManagedAttributes.tsx, 37, 38)) +>P : Symbol(P, Decl(tsxLibraryManagedAttributes.tsx, 37, 55)) + + ? TProps & InferredPropTypes

+>TProps : Symbol(TProps, Decl(tsxLibraryManagedAttributes.tsx, 32, 45)) +>InferredPropTypes : Symbol(InferredPropTypes, Decl(tsxLibraryManagedAttributes.tsx, 3, 25)) +>P : Symbol(P, Decl(tsxLibraryManagedAttributes.tsx, 37, 55)) + + : TProps; +>TProps : Symbol(TProps, Decl(tsxLibraryManagedAttributes.tsx, 32, 45)) +} + +class Component extends ReactComponent { +>Component : Symbol(Component, Decl(tsxLibraryManagedAttributes.tsx, 40, 1)) +>ReactComponent : Symbol(ReactComponent, Decl(tsxLibraryManagedAttributes.tsx, 20, 58)) + + static propTypes = { +>propTypes : Symbol(Component.propTypes, Decl(tsxLibraryManagedAttributes.tsx, 42, 40)) + + foo: PropTypes.number, +>foo : Symbol(foo, Decl(tsxLibraryManagedAttributes.tsx, 43, 24)) +>PropTypes.number : Symbol(PropTypes.number, Decl(tsxLibraryManagedAttributes.tsx, 15, 16)) +>PropTypes : Symbol(PropTypes, Decl(tsxLibraryManagedAttributes.tsx, 12, 1)) +>number : Symbol(PropTypes.number, Decl(tsxLibraryManagedAttributes.tsx, 15, 16)) + + bar: PropTypes.node, +>bar : Symbol(bar, Decl(tsxLibraryManagedAttributes.tsx, 44, 30)) +>PropTypes.node : Symbol(PropTypes.node, Decl(tsxLibraryManagedAttributes.tsx, 17, 16)) +>PropTypes : Symbol(PropTypes, Decl(tsxLibraryManagedAttributes.tsx, 12, 1)) +>node : Symbol(PropTypes.node, Decl(tsxLibraryManagedAttributes.tsx, 17, 16)) + + baz: PropTypes.string.isRequired, +>baz : Symbol(baz, Decl(tsxLibraryManagedAttributes.tsx, 45, 28)) +>PropTypes.string.isRequired : Symbol(PropTypeChecker.isRequired, Decl(tsxLibraryManagedAttributes.tsx, 9, 104)) +>PropTypes.string : Symbol(PropTypes.string, Decl(tsxLibraryManagedAttributes.tsx, 16, 16)) +>PropTypes : Symbol(PropTypes, Decl(tsxLibraryManagedAttributes.tsx, 12, 1)) +>string : Symbol(PropTypes.string, Decl(tsxLibraryManagedAttributes.tsx, 16, 16)) +>isRequired : Symbol(PropTypeChecker.isRequired, Decl(tsxLibraryManagedAttributes.tsx, 9, 104)) + + }; + static defaultProps = { +>defaultProps : Symbol(Component.defaultProps, Decl(tsxLibraryManagedAttributes.tsx, 47, 6)) + + foo: 42, +>foo : Symbol(foo, Decl(tsxLibraryManagedAttributes.tsx, 48, 27)) + } +} + +const a = ; +>a : Symbol(a, Decl(tsxLibraryManagedAttributes.tsx, 53, 5)) +>Component : Symbol(Component, Decl(tsxLibraryManagedAttributes.tsx, 40, 1)) +>foo : Symbol(foo, Decl(tsxLibraryManagedAttributes.tsx, 53, 20)) +>bar : Symbol(bar, Decl(tsxLibraryManagedAttributes.tsx, 53, 29)) +>baz : Symbol(baz, Decl(tsxLibraryManagedAttributes.tsx, 53, 39)) + +const b = ; // Error, missing required prop bar +>b : Symbol(b, Decl(tsxLibraryManagedAttributes.tsx, 54, 5)) +>Component : Symbol(Component, Decl(tsxLibraryManagedAttributes.tsx, 40, 1)) +>foo : Symbol(foo, Decl(tsxLibraryManagedAttributes.tsx, 54, 20)) + +const c = ; +>c : Symbol(c, Decl(tsxLibraryManagedAttributes.tsx, 55, 5)) +>Component : Symbol(Component, Decl(tsxLibraryManagedAttributes.tsx, 40, 1)) +>bar : Symbol(bar, Decl(tsxLibraryManagedAttributes.tsx, 55, 20)) +>baz : Symbol(baz, Decl(tsxLibraryManagedAttributes.tsx, 55, 30)) + +const d = ; // Error, baz not a valid prop +>d : Symbol(d, Decl(tsxLibraryManagedAttributes.tsx, 56, 5)) +>Component : Symbol(Component, Decl(tsxLibraryManagedAttributes.tsx, 40, 1)) +>bar : Symbol(bar, Decl(tsxLibraryManagedAttributes.tsx, 56, 20)) +>baz : Symbol(baz, Decl(tsxLibraryManagedAttributes.tsx, 56, 30)) +>bat : Symbol(bat, Decl(tsxLibraryManagedAttributes.tsx, 56, 39)) + +const e = ; // bar is nullable/undefinable since it's not marked `isRequired` +>e : Symbol(e, Decl(tsxLibraryManagedAttributes.tsx, 57, 5)) +>Component : Symbol(Component, Decl(tsxLibraryManagedAttributes.tsx, 40, 1)) +>foo : Symbol(foo, Decl(tsxLibraryManagedAttributes.tsx, 57, 20)) +>bar : Symbol(bar, Decl(tsxLibraryManagedAttributes.tsx, 57, 29)) +>baz : Symbol(baz, Decl(tsxLibraryManagedAttributes.tsx, 57, 40)) + +const f = ; // Error, baz is _not_ nullable/undefinable since it's marked `isRequired` +>f : Symbol(f, Decl(tsxLibraryManagedAttributes.tsx, 58, 5)) +>Component : Symbol(Component, Decl(tsxLibraryManagedAttributes.tsx, 40, 1)) +>foo : Symbol(foo, Decl(tsxLibraryManagedAttributes.tsx, 58, 20)) +>bar : Symbol(bar, Decl(tsxLibraryManagedAttributes.tsx, 58, 29)) +>baz : Symbol(baz, Decl(tsxLibraryManagedAttributes.tsx, 58, 40)) + +class JustPropTypes extends ReactComponent { +>JustPropTypes : Symbol(JustPropTypes, Decl(tsxLibraryManagedAttributes.tsx, 58, 55)) +>ReactComponent : Symbol(ReactComponent, Decl(tsxLibraryManagedAttributes.tsx, 20, 58)) + + static propTypes = { +>propTypes : Symbol(JustPropTypes.propTypes, Decl(tsxLibraryManagedAttributes.tsx, 60, 44)) + + foo: PropTypes.number, +>foo : Symbol(foo, Decl(tsxLibraryManagedAttributes.tsx, 61, 24)) +>PropTypes.number : Symbol(PropTypes.number, Decl(tsxLibraryManagedAttributes.tsx, 15, 16)) +>PropTypes : Symbol(PropTypes, Decl(tsxLibraryManagedAttributes.tsx, 12, 1)) +>number : Symbol(PropTypes.number, Decl(tsxLibraryManagedAttributes.tsx, 15, 16)) + + bar: PropTypes.node.isRequired, +>bar : Symbol(bar, Decl(tsxLibraryManagedAttributes.tsx, 62, 30)) +>PropTypes.node.isRequired : Symbol(PropTypeChecker.isRequired, Decl(tsxLibraryManagedAttributes.tsx, 9, 104)) +>PropTypes.node : Symbol(PropTypes.node, Decl(tsxLibraryManagedAttributes.tsx, 17, 16)) +>PropTypes : Symbol(PropTypes, Decl(tsxLibraryManagedAttributes.tsx, 12, 1)) +>node : Symbol(PropTypes.node, Decl(tsxLibraryManagedAttributes.tsx, 17, 16)) +>isRequired : Symbol(PropTypeChecker.isRequired, Decl(tsxLibraryManagedAttributes.tsx, 9, 104)) + + }; +} + +const g = ; +>g : Symbol(g, Decl(tsxLibraryManagedAttributes.tsx, 67, 5)) +>JustPropTypes : Symbol(JustPropTypes, Decl(tsxLibraryManagedAttributes.tsx, 58, 55)) +>foo : Symbol(foo, Decl(tsxLibraryManagedAttributes.tsx, 67, 24)) +>bar : Symbol(bar, Decl(tsxLibraryManagedAttributes.tsx, 67, 33)) + +const h = ; // error, wrong type +>h : Symbol(h, Decl(tsxLibraryManagedAttributes.tsx, 68, 5)) +>JustPropTypes : Symbol(JustPropTypes, Decl(tsxLibraryManagedAttributes.tsx, 58, 55)) +>foo : Symbol(foo, Decl(tsxLibraryManagedAttributes.tsx, 68, 24)) + +const i = ; +>i : Symbol(i, Decl(tsxLibraryManagedAttributes.tsx, 69, 5)) +>JustPropTypes : Symbol(JustPropTypes, Decl(tsxLibraryManagedAttributes.tsx, 58, 55)) +>foo : Symbol(foo, Decl(tsxLibraryManagedAttributes.tsx, 69, 24)) +>bar : Symbol(bar, Decl(tsxLibraryManagedAttributes.tsx, 69, 35)) + +const j = ; // error, bar is required +>j : Symbol(j, Decl(tsxLibraryManagedAttributes.tsx, 70, 5)) +>JustPropTypes : Symbol(JustPropTypes, Decl(tsxLibraryManagedAttributes.tsx, 58, 55)) +>foo : Symbol(foo, Decl(tsxLibraryManagedAttributes.tsx, 70, 24)) +>bar : Symbol(bar, Decl(tsxLibraryManagedAttributes.tsx, 70, 33)) + +class JustDefaultProps extends ReactComponent { +>JustDefaultProps : Symbol(JustDefaultProps, Decl(tsxLibraryManagedAttributes.tsx, 70, 48)) +>ReactComponent : Symbol(ReactComponent, Decl(tsxLibraryManagedAttributes.tsx, 20, 58)) + + static defaultProps = { +>defaultProps : Symbol(JustDefaultProps.defaultProps, Decl(tsxLibraryManagedAttributes.tsx, 72, 47)) + + foo: 42, +>foo : Symbol(foo, Decl(tsxLibraryManagedAttributes.tsx, 73, 27)) + + }; +} + +const k = ; +>k : Symbol(k, Decl(tsxLibraryManagedAttributes.tsx, 78, 5)) +>JustDefaultProps : Symbol(JustDefaultProps, Decl(tsxLibraryManagedAttributes.tsx, 70, 48)) +>foo : Symbol(foo, Decl(tsxLibraryManagedAttributes.tsx, 78, 27)) + +const l = ; // error, no prop named bar +>l : Symbol(l, Decl(tsxLibraryManagedAttributes.tsx, 79, 5)) +>JustDefaultProps : Symbol(JustDefaultProps, Decl(tsxLibraryManagedAttributes.tsx, 70, 48)) +>foo : Symbol(foo, Decl(tsxLibraryManagedAttributes.tsx, 79, 27)) +>bar : Symbol(bar, Decl(tsxLibraryManagedAttributes.tsx, 79, 36)) + +const m = ; // error, wrong type +>m : Symbol(m, Decl(tsxLibraryManagedAttributes.tsx, 80, 5)) +>JustDefaultProps : Symbol(JustDefaultProps, Decl(tsxLibraryManagedAttributes.tsx, 70, 48)) +>foo : Symbol(foo, Decl(tsxLibraryManagedAttributes.tsx, 80, 27)) + +interface FooProps { +>FooProps : Symbol(FooProps, Decl(tsxLibraryManagedAttributes.tsx, 80, 40)) + + foo: string; +>foo : Symbol(FooProps.foo, Decl(tsxLibraryManagedAttributes.tsx, 82, 20)) +} + +class BothWithSpecifiedGeneric extends ReactComponent { +>BothWithSpecifiedGeneric : Symbol(BothWithSpecifiedGeneric, Decl(tsxLibraryManagedAttributes.tsx, 84, 1)) +>ReactComponent : Symbol(ReactComponent, Decl(tsxLibraryManagedAttributes.tsx, 20, 58)) +>FooProps : Symbol(FooProps, Decl(tsxLibraryManagedAttributes.tsx, 80, 40)) + + static propTypes = { +>propTypes : Symbol(BothWithSpecifiedGeneric.propTypes, Decl(tsxLibraryManagedAttributes.tsx, 86, 65)) + + foo: PropTypes.string, +>foo : Symbol(foo, Decl(tsxLibraryManagedAttributes.tsx, 87, 24)) +>PropTypes.string : Symbol(PropTypes.string, Decl(tsxLibraryManagedAttributes.tsx, 16, 16)) +>PropTypes : Symbol(PropTypes, Decl(tsxLibraryManagedAttributes.tsx, 12, 1)) +>string : Symbol(PropTypes.string, Decl(tsxLibraryManagedAttributes.tsx, 16, 16)) + + bar: PropTypes.node, +>bar : Symbol(bar, Decl(tsxLibraryManagedAttributes.tsx, 88, 30)) +>PropTypes.node : Symbol(PropTypes.node, Decl(tsxLibraryManagedAttributes.tsx, 17, 16)) +>PropTypes : Symbol(PropTypes, Decl(tsxLibraryManagedAttributes.tsx, 12, 1)) +>node : Symbol(PropTypes.node, Decl(tsxLibraryManagedAttributes.tsx, 17, 16)) + + baz: PropTypes.number.isRequired, +>baz : Symbol(baz, Decl(tsxLibraryManagedAttributes.tsx, 89, 28)) +>PropTypes.number.isRequired : Symbol(PropTypeChecker.isRequired, Decl(tsxLibraryManagedAttributes.tsx, 9, 104)) +>PropTypes.number : Symbol(PropTypes.number, Decl(tsxLibraryManagedAttributes.tsx, 15, 16)) +>PropTypes : Symbol(PropTypes, Decl(tsxLibraryManagedAttributes.tsx, 12, 1)) +>number : Symbol(PropTypes.number, Decl(tsxLibraryManagedAttributes.tsx, 15, 16)) +>isRequired : Symbol(PropTypeChecker.isRequired, Decl(tsxLibraryManagedAttributes.tsx, 9, 104)) + + }; + static defaultProps = { +>defaultProps : Symbol(BothWithSpecifiedGeneric.defaultProps, Decl(tsxLibraryManagedAttributes.tsx, 91, 6)) + + foo: "yo", +>foo : Symbol(foo, Decl(tsxLibraryManagedAttributes.tsx, 92, 27)) + + }; +} +const n = ; +>n : Symbol(n, Decl(tsxLibraryManagedAttributes.tsx, 96, 5)) +>BothWithSpecifiedGeneric : Symbol(BothWithSpecifiedGeneric, Decl(tsxLibraryManagedAttributes.tsx, 84, 1)) +>foo : Symbol(foo, Decl(tsxLibraryManagedAttributes.tsx, 96, 35)) +>bar : Symbol(bar, Decl(tsxLibraryManagedAttributes.tsx, 96, 46)) +>baz : Symbol(baz, Decl(tsxLibraryManagedAttributes.tsx, 96, 56)) + +const o = ; // Error, missing required prop bar +>o : Symbol(o, Decl(tsxLibraryManagedAttributes.tsx, 97, 5)) +>BothWithSpecifiedGeneric : Symbol(BothWithSpecifiedGeneric, Decl(tsxLibraryManagedAttributes.tsx, 84, 1)) +>foo : Symbol(foo, Decl(tsxLibraryManagedAttributes.tsx, 97, 35)) + +const p = ; +>p : Symbol(p, Decl(tsxLibraryManagedAttributes.tsx, 98, 5)) +>BothWithSpecifiedGeneric : Symbol(BothWithSpecifiedGeneric, Decl(tsxLibraryManagedAttributes.tsx, 84, 1)) +>bar : Symbol(bar, Decl(tsxLibraryManagedAttributes.tsx, 98, 35)) +>baz : Symbol(baz, Decl(tsxLibraryManagedAttributes.tsx, 98, 45)) + +const q = ; // Error, baz not a valid prop +>q : Symbol(q, Decl(tsxLibraryManagedAttributes.tsx, 99, 5)) +>BothWithSpecifiedGeneric : Symbol(BothWithSpecifiedGeneric, Decl(tsxLibraryManagedAttributes.tsx, 84, 1)) +>bar : Symbol(bar, Decl(tsxLibraryManagedAttributes.tsx, 99, 35)) +>baz : Symbol(baz, Decl(tsxLibraryManagedAttributes.tsx, 99, 45)) +>bat : Symbol(bat, Decl(tsxLibraryManagedAttributes.tsx, 99, 54)) + +const r = ; // bar is nullable/undefinable since it's not marked `isRequired` +>r : Symbol(r, Decl(tsxLibraryManagedAttributes.tsx, 100, 5)) +>BothWithSpecifiedGeneric : Symbol(BothWithSpecifiedGeneric, Decl(tsxLibraryManagedAttributes.tsx, 84, 1)) +>foo : Symbol(foo, Decl(tsxLibraryManagedAttributes.tsx, 100, 35)) +>bar : Symbol(bar, Decl(tsxLibraryManagedAttributes.tsx, 100, 44)) +>baz : Symbol(baz, Decl(tsxLibraryManagedAttributes.tsx, 100, 55)) + +const s = ; // Error, baz is _not_ nullable/undefinable since it's marked `isRequired` +>s : Symbol(s, Decl(tsxLibraryManagedAttributes.tsx, 101, 5)) +>BothWithSpecifiedGeneric : Symbol(BothWithSpecifiedGeneric, Decl(tsxLibraryManagedAttributes.tsx, 84, 1)) +>foo : Symbol(foo, Decl(tsxLibraryManagedAttributes.tsx, 101, 35)) +>bar : Symbol(bar, Decl(tsxLibraryManagedAttributes.tsx, 101, 44)) +>baz : Symbol(baz, Decl(tsxLibraryManagedAttributes.tsx, 101, 55)) + +class JustPropTypesWithSpecifiedGeneric extends ReactComponent { +>JustPropTypesWithSpecifiedGeneric : Symbol(JustPropTypesWithSpecifiedGeneric, Decl(tsxLibraryManagedAttributes.tsx, 101, 70)) +>ReactComponent : Symbol(ReactComponent, Decl(tsxLibraryManagedAttributes.tsx, 20, 58)) +>FooProps : Symbol(FooProps, Decl(tsxLibraryManagedAttributes.tsx, 80, 40)) + + static propTypes = { +>propTypes : Symbol(JustPropTypesWithSpecifiedGeneric.propTypes, Decl(tsxLibraryManagedAttributes.tsx, 103, 74)) + + foo: PropTypes.string, +>foo : Symbol(foo, Decl(tsxLibraryManagedAttributes.tsx, 104, 24)) +>PropTypes.string : Symbol(PropTypes.string, Decl(tsxLibraryManagedAttributes.tsx, 16, 16)) +>PropTypes : Symbol(PropTypes, Decl(tsxLibraryManagedAttributes.tsx, 12, 1)) +>string : Symbol(PropTypes.string, Decl(tsxLibraryManagedAttributes.tsx, 16, 16)) + + bar: PropTypes.node.isRequired, +>bar : Symbol(bar, Decl(tsxLibraryManagedAttributes.tsx, 105, 30)) +>PropTypes.node.isRequired : Symbol(PropTypeChecker.isRequired, Decl(tsxLibraryManagedAttributes.tsx, 9, 104)) +>PropTypes.node : Symbol(PropTypes.node, Decl(tsxLibraryManagedAttributes.tsx, 17, 16)) +>PropTypes : Symbol(PropTypes, Decl(tsxLibraryManagedAttributes.tsx, 12, 1)) +>node : Symbol(PropTypes.node, Decl(tsxLibraryManagedAttributes.tsx, 17, 16)) +>isRequired : Symbol(PropTypeChecker.isRequired, Decl(tsxLibraryManagedAttributes.tsx, 9, 104)) + + }; +} +const t = ; +>t : Symbol(t, Decl(tsxLibraryManagedAttributes.tsx, 109, 5)) +>JustPropTypesWithSpecifiedGeneric : Symbol(JustPropTypesWithSpecifiedGeneric, Decl(tsxLibraryManagedAttributes.tsx, 101, 70)) +>foo : Symbol(foo, Decl(tsxLibraryManagedAttributes.tsx, 109, 44)) +>bar : Symbol(bar, Decl(tsxLibraryManagedAttributes.tsx, 109, 55)) + +const u = ; // error, wrong type +>u : Symbol(u, Decl(tsxLibraryManagedAttributes.tsx, 110, 5)) +>JustPropTypesWithSpecifiedGeneric : Symbol(JustPropTypesWithSpecifiedGeneric, Decl(tsxLibraryManagedAttributes.tsx, 101, 70)) +>foo : Symbol(foo, Decl(tsxLibraryManagedAttributes.tsx, 110, 44)) + +const v = ; // generic overrides propTypes required-ness, null isn't valid +>v : Symbol(v, Decl(tsxLibraryManagedAttributes.tsx, 111, 5)) +>JustPropTypesWithSpecifiedGeneric : Symbol(JustPropTypesWithSpecifiedGeneric, Decl(tsxLibraryManagedAttributes.tsx, 101, 70)) +>foo : Symbol(foo, Decl(tsxLibraryManagedAttributes.tsx, 111, 44)) +>bar : Symbol(bar, Decl(tsxLibraryManagedAttributes.tsx, 111, 55)) + +const w = ; // error, bar is required +>w : Symbol(w, Decl(tsxLibraryManagedAttributes.tsx, 112, 5)) +>JustPropTypesWithSpecifiedGeneric : Symbol(JustPropTypesWithSpecifiedGeneric, Decl(tsxLibraryManagedAttributes.tsx, 101, 70)) +>foo : Symbol(foo, Decl(tsxLibraryManagedAttributes.tsx, 112, 44)) +>bar : Symbol(bar, Decl(tsxLibraryManagedAttributes.tsx, 112, 55)) + +class JustDefaultPropsWithSpecifiedGeneric extends ReactComponent { +>JustDefaultPropsWithSpecifiedGeneric : Symbol(JustDefaultPropsWithSpecifiedGeneric, Decl(tsxLibraryManagedAttributes.tsx, 112, 70)) +>ReactComponent : Symbol(ReactComponent, Decl(tsxLibraryManagedAttributes.tsx, 20, 58)) +>FooProps : Symbol(FooProps, Decl(tsxLibraryManagedAttributes.tsx, 80, 40)) + + static defaultProps = { +>defaultProps : Symbol(JustDefaultPropsWithSpecifiedGeneric.defaultProps, Decl(tsxLibraryManagedAttributes.tsx, 114, 77)) + + foo: "no", +>foo : Symbol(foo, Decl(tsxLibraryManagedAttributes.tsx, 115, 27)) + + }; +} + +const x = ; +>x : Symbol(x, Decl(tsxLibraryManagedAttributes.tsx, 120, 5)) +>JustDefaultPropsWithSpecifiedGeneric : Symbol(JustDefaultPropsWithSpecifiedGeneric, Decl(tsxLibraryManagedAttributes.tsx, 112, 70)) +>foo : Symbol(foo, Decl(tsxLibraryManagedAttributes.tsx, 120, 47)) + +const y = ; // error, no prop named bar +>y : Symbol(y, Decl(tsxLibraryManagedAttributes.tsx, 121, 5)) +>JustDefaultPropsWithSpecifiedGeneric : Symbol(JustDefaultPropsWithSpecifiedGeneric, Decl(tsxLibraryManagedAttributes.tsx, 112, 70)) +>foo : Symbol(foo, Decl(tsxLibraryManagedAttributes.tsx, 121, 47)) +>bar : Symbol(bar, Decl(tsxLibraryManagedAttributes.tsx, 121, 56)) + +const z = ; // error, wrong type +>z : Symbol(z, Decl(tsxLibraryManagedAttributes.tsx, 122, 5)) +>JustDefaultPropsWithSpecifiedGeneric : Symbol(JustDefaultPropsWithSpecifiedGeneric, Decl(tsxLibraryManagedAttributes.tsx, 112, 70)) +>foo : Symbol(foo, Decl(tsxLibraryManagedAttributes.tsx, 122, 47)) + +const aa = ; +>aa : Symbol(aa, Decl(tsxLibraryManagedAttributes.tsx, 123, 5)) +>JustDefaultPropsWithSpecifiedGeneric : Symbol(JustDefaultPropsWithSpecifiedGeneric, Decl(tsxLibraryManagedAttributes.tsx, 112, 70)) + diff --git a/tests/baselines/reference/tsxLibraryManagedAttributes.types b/tests/baselines/reference/tsxLibraryManagedAttributes.types new file mode 100644 index 0000000000000..e24e9115aff1d --- /dev/null +++ b/tests/baselines/reference/tsxLibraryManagedAttributes.types @@ -0,0 +1,551 @@ +=== tests/cases/conformance/jsx/tsxLibraryManagedAttributes.tsx === +type Defaultize = +>Defaultize : Defaultize +>TProps : TProps +>TDefaults : TDefaults + + & {[K in Extract]?: TProps[K]} +>K : K +>Extract : Extract +>TProps : TProps +>TDefaults : TDefaults +>TProps : TProps +>K : K + + & {[K in Exclude]: TProps[K]} +>K : K +>Exclude : Exclude +>TProps : TProps +>TDefaults : TDefaults +>TProps : TProps +>K : K + + & Partial; +>Partial : Partial +>TDefaults : TDefaults + +type InferredPropTypes

= {[K in keyof P]: P[K] extends PropTypeChecker ? PropTypeChecker[typeof checkedType] : {}}; +>InferredPropTypes : InferredPropTypes

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

+>P : P +>D : D + + : TComponent extends { defaultProps: infer D } +>TComponent : TComponent +>defaultProps : D +>D : D + + ? Defaultize +>Defaultize : Defaultize +>TProps : TProps +>D : D + + : TComponent extends { propTypes: infer P } +>TComponent : TComponent +>propTypes : P +>P : P + + ? TProps & InferredPropTypes

+>TProps : TProps +>InferredPropTypes : InferredPropTypes

+>P : P + + : TProps; +>TProps : TProps +} + +class Component extends ReactComponent { +>Component : Component +>ReactComponent : ReactComponent<{}, {}> + + static propTypes = { +>propTypes : { foo: PropTypeChecker; bar: PropTypeChecker; baz: PropTypeChecker; } +>{ foo: PropTypes.number, bar: PropTypes.node, baz: PropTypes.string.isRequired, } : { foo: PropTypeChecker; bar: PropTypeChecker; baz: PropTypeChecker; } + + foo: PropTypes.number, +>foo : PropTypeChecker +>PropTypes.number : PropTypeChecker +>PropTypes : typeof PropTypes +>number : PropTypeChecker + + bar: PropTypes.node, +>bar : PropTypeChecker +>PropTypes.node : PropTypeChecker +>PropTypes : typeof PropTypes +>node : PropTypeChecker + + baz: PropTypes.string.isRequired, +>baz : PropTypeChecker +>PropTypes.string.isRequired : PropTypeChecker +>PropTypes.string : PropTypeChecker +>PropTypes : typeof PropTypes +>string : PropTypeChecker +>isRequired : PropTypeChecker + + }; + static defaultProps = { +>defaultProps : { foo: number; } +>{ foo: 42, } : { foo: number; } + + foo: 42, +>foo : number +>42 : 42 + } +} + +const a = ; +>a : JSX.Element +> : JSX.Element +>Component : typeof Component +>foo : number +>12 : 12 +>bar : string +>baz : string + +const b = ; // Error, missing required prop bar +>b : JSX.Element +> : JSX.Element +>Component : typeof Component +>foo : number +>12 : 12 + +const c = ; +>c : JSX.Element +> : JSX.Element +>Component : typeof Component +>bar : string +>baz : string + +const d = ; // Error, baz not a valid prop +>d : JSX.Element +> : JSX.Element +>Component : typeof Component +>bar : string +>baz : string +>bat : string + +const e = ; // bar is nullable/undefinable since it's not marked `isRequired` +>e : JSX.Element +> : JSX.Element +>Component : typeof Component +>foo : number +>12 : 12 +>bar : null +>null : null +>baz : string + +const f = ; // Error, baz is _not_ nullable/undefinable since it's marked `isRequired` +>f : JSX.Element +> : JSX.Element +>Component : typeof Component +>foo : number +>12 : 12 +>bar : string +>baz : null +>null : null + +class JustPropTypes extends ReactComponent { +>JustPropTypes : JustPropTypes +>ReactComponent : ReactComponent<{}, {}> + + static propTypes = { +>propTypes : { foo: PropTypeChecker; bar: PropTypeChecker; } +>{ foo: PropTypes.number, bar: PropTypes.node.isRequired, } : { foo: PropTypeChecker; bar: PropTypeChecker; } + + foo: PropTypes.number, +>foo : PropTypeChecker +>PropTypes.number : PropTypeChecker +>PropTypes : typeof PropTypes +>number : PropTypeChecker + + bar: PropTypes.node.isRequired, +>bar : PropTypeChecker +>PropTypes.node.isRequired : PropTypeChecker +>PropTypes.node : PropTypeChecker +>PropTypes : typeof PropTypes +>node : PropTypeChecker +>isRequired : PropTypeChecker + + }; +} + +const g = ; +>g : JSX.Element +> : JSX.Element +>JustPropTypes : typeof JustPropTypes +>foo : number +>12 : 12 +>bar : string + +const h = ; // error, wrong type +>h : JSX.Element +> : JSX.Element +>JustPropTypes : typeof JustPropTypes +>foo : string + +const i = ; +>i : JSX.Element +> : JSX.Element +>JustPropTypes : typeof JustPropTypes +>foo : null +>null : null +>bar : string + +const j = ; // error, bar is required +>j : JSX.Element +> : JSX.Element +>JustPropTypes : typeof JustPropTypes +>foo : number +>12 : 12 +>bar : null +>null : null + +class JustDefaultProps extends ReactComponent { +>JustDefaultProps : JustDefaultProps +>ReactComponent : ReactComponent<{}, {}> + + static defaultProps = { +>defaultProps : { foo: number; } +>{ foo: 42, } : { foo: number; } + + foo: 42, +>foo : number +>42 : 42 + + }; +} + +const k = ; +>k : JSX.Element +> : JSX.Element +>JustDefaultProps : typeof JustDefaultProps +>foo : number +>12 : 12 + +const l = ; // error, no prop named bar +>l : JSX.Element +> : JSX.Element +>JustDefaultProps : typeof JustDefaultProps +>foo : number +>12 : 12 +>bar : string + +const m = ; // error, wrong type +>m : JSX.Element +> : JSX.Element +>JustDefaultProps : typeof JustDefaultProps +>foo : string + +interface FooProps { +>FooProps : FooProps + + foo: string; +>foo : string +} + +class BothWithSpecifiedGeneric extends ReactComponent { +>BothWithSpecifiedGeneric : BothWithSpecifiedGeneric +>ReactComponent : ReactComponent +>FooProps : FooProps + + static propTypes = { +>propTypes : { foo: PropTypeChecker; bar: PropTypeChecker; baz: PropTypeChecker; } +>{ foo: PropTypes.string, bar: PropTypes.node, baz: PropTypes.number.isRequired, } : { foo: PropTypeChecker; bar: PropTypeChecker; baz: PropTypeChecker; } + + foo: PropTypes.string, +>foo : PropTypeChecker +>PropTypes.string : PropTypeChecker +>PropTypes : typeof PropTypes +>string : PropTypeChecker + + bar: PropTypes.node, +>bar : PropTypeChecker +>PropTypes.node : PropTypeChecker +>PropTypes : typeof PropTypes +>node : PropTypeChecker + + baz: PropTypes.number.isRequired, +>baz : PropTypeChecker +>PropTypes.number.isRequired : PropTypeChecker +>PropTypes.number : PropTypeChecker +>PropTypes : typeof PropTypes +>number : PropTypeChecker +>isRequired : PropTypeChecker + + }; + static defaultProps = { +>defaultProps : { foo: string; } +>{ foo: "yo", } : { foo: string; } + + foo: "yo", +>foo : string +>"yo" : "yo" + + }; +} +const n = ; +>n : JSX.Element +> : JSX.Element +>BothWithSpecifiedGeneric : typeof BothWithSpecifiedGeneric +>foo : string +>bar : string +>baz : number +>12 : 12 + +const o = ; // Error, missing required prop bar +>o : JSX.Element +> : JSX.Element +>BothWithSpecifiedGeneric : typeof BothWithSpecifiedGeneric +>foo : string + +const p = ; +>p : JSX.Element +> : JSX.Element +>BothWithSpecifiedGeneric : typeof BothWithSpecifiedGeneric +>bar : string +>baz : number +>12 : 12 + +const q = ; // Error, baz not a valid prop +>q : JSX.Element +> : JSX.Element +>BothWithSpecifiedGeneric : typeof BothWithSpecifiedGeneric +>bar : string +>baz : number +>12 : 12 +>bat : string + +const r = ; // bar is nullable/undefinable since it's not marked `isRequired` +>r : JSX.Element +> : JSX.Element +>BothWithSpecifiedGeneric : typeof BothWithSpecifiedGeneric +>foo : string +>bar : null +>null : null +>baz : number +>0 : 0 + +const s = ; // Error, baz is _not_ nullable/undefinable since it's marked `isRequired` +>s : JSX.Element +> : JSX.Element +>BothWithSpecifiedGeneric : typeof BothWithSpecifiedGeneric +>foo : string +>bar : string +>baz : null +>null : null + +class JustPropTypesWithSpecifiedGeneric extends ReactComponent { +>JustPropTypesWithSpecifiedGeneric : JustPropTypesWithSpecifiedGeneric +>ReactComponent : ReactComponent +>FooProps : FooProps + + static propTypes = { +>propTypes : { foo: PropTypeChecker; bar: PropTypeChecker; } +>{ foo: PropTypes.string, bar: PropTypes.node.isRequired, } : { foo: PropTypeChecker; bar: PropTypeChecker; } + + foo: PropTypes.string, +>foo : PropTypeChecker +>PropTypes.string : PropTypeChecker +>PropTypes : typeof PropTypes +>string : PropTypeChecker + + bar: PropTypes.node.isRequired, +>bar : PropTypeChecker +>PropTypes.node.isRequired : PropTypeChecker +>PropTypes.node : PropTypeChecker +>PropTypes : typeof PropTypes +>node : PropTypeChecker +>isRequired : PropTypeChecker + + }; +} +const t = ; +>t : JSX.Element +> : JSX.Element +>JustPropTypesWithSpecifiedGeneric : typeof JustPropTypesWithSpecifiedGeneric +>foo : string +>bar : string + +const u = ; // error, wrong type +>u : JSX.Element +> : JSX.Element +>JustPropTypesWithSpecifiedGeneric : typeof JustPropTypesWithSpecifiedGeneric +>foo : number +>12 : 12 + +const v = ; // generic overrides propTypes required-ness, null isn't valid +>v : JSX.Element +> : JSX.Element +>JustPropTypesWithSpecifiedGeneric : typeof JustPropTypesWithSpecifiedGeneric +>foo : null +>null : null +>bar : string + +const w = ; // error, bar is required +>w : JSX.Element +> : JSX.Element +>JustPropTypesWithSpecifiedGeneric : typeof JustPropTypesWithSpecifiedGeneric +>foo : string +>bar : null +>null : null + +class JustDefaultPropsWithSpecifiedGeneric extends ReactComponent { +>JustDefaultPropsWithSpecifiedGeneric : JustDefaultPropsWithSpecifiedGeneric +>ReactComponent : ReactComponent +>FooProps : FooProps + + static defaultProps = { +>defaultProps : { foo: string; } +>{ foo: "no", } : { foo: string; } + + foo: "no", +>foo : string +>"no" : "no" + + }; +} + +const x = ; +>x : JSX.Element +> : JSX.Element +>JustDefaultPropsWithSpecifiedGeneric : typeof JustDefaultPropsWithSpecifiedGeneric +>foo : string + +const y = ; // error, no prop named bar +>y : JSX.Element +> : JSX.Element +>JustDefaultPropsWithSpecifiedGeneric : typeof JustDefaultPropsWithSpecifiedGeneric +>foo : string +>bar : string + +const z = ; // error, wrong type +>z : JSX.Element +> : JSX.Element +>JustDefaultPropsWithSpecifiedGeneric : typeof JustDefaultPropsWithSpecifiedGeneric +>foo : number +>12 : 12 + +const aa = ; +>aa : JSX.Element +> : JSX.Element +>JustDefaultPropsWithSpecifiedGeneric : typeof JustDefaultPropsWithSpecifiedGeneric + diff --git a/tests/cases/conformance/jsx/tsxLibraryManagedAttributes.tsx b/tests/cases/conformance/jsx/tsxLibraryManagedAttributes.tsx new file mode 100644 index 0000000000000..051c0db899489 --- /dev/null +++ b/tests/cases/conformance/jsx/tsxLibraryManagedAttributes.tsx @@ -0,0 +1,127 @@ +// @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 = ;