Always call checkExpression on JSX attribute values

Fixes #13676
This commit is contained in:
Ryan Cavanaugh
2017-01-25 10:40:59 -08:00
parent abc30b26c7
commit 76b1e95c3d
5 changed files with 239 additions and 9 deletions

View File

@@ -11879,6 +11879,16 @@ namespace ts {
function checkJsxAttribute(node: JsxAttribute, elementAttributesType: Type, nameTable: Map<boolean>) {
let correspondingPropType: Type = undefined;
// We need to unconditionally get the expression type
let exprType: Type;
if (node.initializer) {
exprType = checkExpression(node.initializer);
}
else {
// <Elem attr /> is sugar for <Elem attr={true} />
exprType = booleanType;
}
// Look up the corresponding property for this attribute
if (elementAttributesType === emptyObjectType && isUnhyphenatedJsxName(node.name.text)) {
// If there is no 'props' property, you may not have non-"data-" attributes
@@ -11902,15 +11912,6 @@ namespace ts {
}
}
let exprType: Type;
if (node.initializer) {
exprType = checkExpression(node.initializer);
}
else {
// <Elem attr /> is sugar for <Elem attr={true} />
exprType = booleanType;
}
if (correspondingPropType) {
checkTypeAssignableTo(exprType, correspondingPropType, node);
}