diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c1b57e5def701..ca73d92e0c014 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14802,6 +14802,12 @@ namespace ts { } } + function checkJsxAttribute(node: JsxAttribute, checkMode?: CheckMode) { + return node.initializer + ? checkExpressionForMutableLocation(node.initializer, checkMode) + : trueType; // is sugar for + } + /** * Get attributes type of the JSX opening-like element. The result is from resolving "attributes" property of the opening-like element. * @@ -14824,9 +14830,7 @@ namespace ts { for (const attributeDecl of attributes.properties) { const member = attributeDecl.symbol; if (isJsxAttribute(attributeDecl)) { - const exprType = attributeDecl.initializer ? - checkExpression(attributeDecl.initializer, checkMode) : - trueType; // is sugar for + const exprType = checkJsxAttribute(attributeDecl, checkMode); const attributeSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient | member.flags, member.escapedName); attributeSymbol.declarations = member.declarations; diff --git a/tests/baselines/reference/checkJsxChildrenProperty14.errors.txt b/tests/baselines/reference/checkJsxChildrenProperty14.errors.txt index ecae349e19e63..ca12d59c2fd99 100644 --- a/tests/baselines/reference/checkJsxChildrenProperty14.errors.txt +++ b/tests/baselines/reference/checkJsxChildrenProperty14.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/jsx/file.tsx(42,27): error TS2322: Type '{ a: 10; b: "hi"; children: Element[]; }' is not assignable to type 'IntrinsicAttributes & SingleChildProp'. - Type '{ a: 10; b: "hi"; children: Element[]; }' is not assignable to type 'SingleChildProp'. +tests/cases/conformance/jsx/file.tsx(42,27): error TS2322: Type '{ a: number; b: string; children: Element[]; }' is not assignable to type 'IntrinsicAttributes & SingleChildProp'. + Type '{ a: number; b: string; children: Element[]; }' is not assignable to type 'SingleChildProp'. Types of property 'children' are incompatible. Type 'Element[]' is not assignable to type 'Element'. Property 'type' is missing in type 'Element[]'. @@ -49,8 +49,8 @@ tests/cases/conformance/jsx/file.tsx(42,27): error TS2322: Type '{ a: 10; b: "hi // Error let k5 = <>