mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-14 19:16:17 -06:00
Include type parameter constrains in literal type context determination
This commit is contained in:
parent
01a33f707c
commit
614d171a21
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user