diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f5f82917b877b..3bf36232e466a 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -29186,7 +29186,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } function getContextualTypeForChildJsxExpression(node: JsxElement, child: JsxChild, contextFlags: ContextFlags | undefined) { - const attributesType = getApparentTypeOfContextualType(node.openingElement.tagName, contextFlags); + const attributesType = getApparentTypeOfContextualType(node.openingElement.attributes, contextFlags); // JSX expression is in children of JSX Element, we will look for an "children" attribute (we get the name from JSX.ElementAttributesProperty) const jsxChildrenPropertyName = getJsxElementChildrenPropertyName(getJsxNamespaceAt(node)); if (!(attributesType && !isTypeAny(attributesType) && jsxChildrenPropertyName && jsxChildrenPropertyName !== "")) { diff --git a/tests/baselines/reference/checkJsxChildrenProperty16.symbols b/tests/baselines/reference/checkJsxChildrenProperty16.symbols new file mode 100644 index 0000000000000..32806ee98cfae --- /dev/null +++ b/tests/baselines/reference/checkJsxChildrenProperty16.symbols @@ -0,0 +1,63 @@ +=== tests/cases/conformance/jsx/checkJsxChildrenProperty16.tsx === +/// + +// repro from #53493 + +import React = require('react'); +>React : Symbol(React, Decl(checkJsxChildrenProperty16.tsx, 0, 0)) + +export type Props = +>Props : Symbol(Props, Decl(checkJsxChildrenProperty16.tsx, 4, 32)) + + | { renderNumber?: false; children: (arg: string) => void } +>renderNumber : Symbol(renderNumber, Decl(checkJsxChildrenProperty16.tsx, 7, 5)) +>children : Symbol(children, Decl(checkJsxChildrenProperty16.tsx, 7, 27)) +>arg : Symbol(arg, Decl(checkJsxChildrenProperty16.tsx, 7, 39)) + + | { + renderNumber: true; +>renderNumber : Symbol(renderNumber, Decl(checkJsxChildrenProperty16.tsx, 8, 5)) + + children: (arg: number) => void; +>children : Symbol(children, Decl(checkJsxChildrenProperty16.tsx, 9, 25)) +>arg : Symbol(arg, Decl(checkJsxChildrenProperty16.tsx, 10, 17)) + + }; + +export declare function Foo(props: Props): JSX.Element; +>Foo : Symbol(Foo, Decl(checkJsxChildrenProperty16.tsx, 11, 6)) +>props : Symbol(props, Decl(checkJsxChildrenProperty16.tsx, 13, 28)) +>Props : Symbol(Props, Decl(checkJsxChildrenProperty16.tsx, 4, 32)) +>JSX : Symbol(JSX, Decl(react16.d.ts, 2493, 12)) +>Element : Symbol(JSX.Element, Decl(react16.d.ts, 2494, 23)) + +export const Test = () => { +>Test : Symbol(Test, Decl(checkJsxChildrenProperty16.tsx, 15, 12)) + + return ( + <> + {(value) => {}} +>Foo : Symbol(Foo, Decl(checkJsxChildrenProperty16.tsx, 11, 6)) +>value : Symbol(value, Decl(checkJsxChildrenProperty16.tsx, 18, 13)) +>Foo : Symbol(Foo, Decl(checkJsxChildrenProperty16.tsx, 11, 6)) + + {(value) => {}} +>Foo : Symbol(Foo, Decl(checkJsxChildrenProperty16.tsx, 11, 6)) +>renderNumber : Symbol(renderNumber, Decl(checkJsxChildrenProperty16.tsx, 19, 10)) +>value : Symbol(value, Decl(checkJsxChildrenProperty16.tsx, 19, 26)) +>Foo : Symbol(Foo, Decl(checkJsxChildrenProperty16.tsx, 11, 6)) + + {}} /> +>Foo : Symbol(Foo, Decl(checkJsxChildrenProperty16.tsx, 11, 6)) +>children : Symbol(children, Decl(checkJsxChildrenProperty16.tsx, 21, 10)) +>value : Symbol(value, Decl(checkJsxChildrenProperty16.tsx, 21, 22)) + + {}} /> +>Foo : Symbol(Foo, Decl(checkJsxChildrenProperty16.tsx, 11, 6)) +>renderNumber : Symbol(renderNumber, Decl(checkJsxChildrenProperty16.tsx, 22, 10)) +>children : Symbol(children, Decl(checkJsxChildrenProperty16.tsx, 22, 23)) +>value : Symbol(value, Decl(checkJsxChildrenProperty16.tsx, 22, 35)) + + + ); +}; diff --git a/tests/baselines/reference/checkJsxChildrenProperty16.types b/tests/baselines/reference/checkJsxChildrenProperty16.types new file mode 100644 index 0000000000000..bf10ebff297bf --- /dev/null +++ b/tests/baselines/reference/checkJsxChildrenProperty16.types @@ -0,0 +1,76 @@ +=== tests/cases/conformance/jsx/checkJsxChildrenProperty16.tsx === +/// + +// repro from #53493 + +import React = require('react'); +>React : typeof React + +export type Props = +>Props : { renderNumber?: false | undefined; children: (arg: string) => void; } | { renderNumber: true; children: (arg: number) => void; } + + | { renderNumber?: false; children: (arg: string) => void } +>renderNumber : false | undefined +>false : false +>children : (arg: string) => void +>arg : string + + | { + renderNumber: true; +>renderNumber : true +>true : true + + children: (arg: number) => void; +>children : (arg: number) => void +>arg : number + + }; + +export declare function Foo(props: Props): JSX.Element; +>Foo : (props: Props) => JSX.Element +>props : Props +>JSX : any + +export const Test = () => { +>Test : () => JSX.Element +>() => { return ( <> {(value) => {}} {(value) => {}} {}} /> {}} /> );} : () => JSX.Element + + return ( +>( <> {(value) => {}} {(value) => {}} {}} /> {}} /> ) : JSX.Element + + <> +><> {(value) => {}} {(value) => {}} {}} /> {}} /> : JSX.Element + + {(value) => {}} +>{(value) => {}} : JSX.Element +>Foo : (props: Props) => JSX.Element +>(value) => {} : (value: string) => void +>value : string +>Foo : (props: Props) => JSX.Element + + {(value) => {}} +>{(value) => {}} : JSX.Element +>Foo : (props: Props) => JSX.Element +>renderNumber : true +>(value) => {} : (value: number) => void +>value : number +>Foo : (props: Props) => JSX.Element + + {}} /> +> {}} /> : JSX.Element +>Foo : (props: Props) => JSX.Element +>children : (value: string) => void +>(value) => {} : (value: string) => void +>value : string + + {}} /> +> {}} /> : JSX.Element +>Foo : (props: Props) => JSX.Element +>renderNumber : true +>children : (value: number) => void +>(value) => {} : (value: number) => void +>value : number + + + ); +}; diff --git a/tests/cases/conformance/jsx/checkJsxChildrenProperty16.tsx b/tests/cases/conformance/jsx/checkJsxChildrenProperty16.tsx new file mode 100644 index 0000000000000..cf1f81f4bac26 --- /dev/null +++ b/tests/cases/conformance/jsx/checkJsxChildrenProperty16.tsx @@ -0,0 +1,30 @@ +// @strict: true +// @noEmit: true +// @jsx: preserve + +/// + +// repro from #53493 + +import React = require('react'); + +export type Props = + | { renderNumber?: false; children: (arg: string) => void } + | { + renderNumber: true; + children: (arg: number) => void; + }; + +export declare function Foo(props: Props): JSX.Element; + +export const Test = () => { + return ( + <> + {(value) => {}} + {(value) => {}} + + {}} /> + {}} /> + + ); +}; \ No newline at end of file