Include type parameter constrains in literal type context determination

This commit is contained in:
Anders Hejlsberg 2016-07-16 14:45:38 -07:00
parent 01a33f707c
commit 614d171a21

View File

@ -13007,8 +13007,22 @@ namespace ts {
false;
}
function hasLiteralContextualType(node: Expression) {
const contextualType = getContextualType(node);
if (!contextualType) {
return false;
}
if (contextualType.flags & TypeFlags.TypeParameter) {
const apparentType = getApparentTypeOfTypeParameter(<TypeParameter>contextualType);
if (apparentType.flags & (TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.BooleanLike)) {
return true;
}
}
return isLiteralUnionType(contextualType);
}
function isLiteralTypeContext(node: Expression) {
return isLiteralTypeLocation(node) || isLiteralUnionType(getContextualType(node) || unknownType);
return isLiteralTypeLocation(node) || hasLiteralContextualType(node);
}
function checkLiteralExpression(node: Expression): Type {