Retain literal type for prefix plus on number literal

This commit is contained in:
ikatyang
2017-07-26 14:39:26 +08:00
parent f667357aad
commit eee6851911
8 changed files with 54 additions and 19 deletions

View File

@@ -16952,9 +16952,13 @@ namespace ts {
if (operandType === silentNeverType) {
return silentNeverType;
}
if (node.operator === SyntaxKind.MinusToken && node.operand.kind === SyntaxKind.NumericLiteral) {
const isOperandNumericLiteral = node.operand.kind === SyntaxKind.NumericLiteral;
if (isOperandNumericLiteral && node.operator === SyntaxKind.MinusToken) {
return getFreshTypeOfLiteralType(getLiteralType(-(<LiteralExpression>node.operand).text));
}
if (isOperandNumericLiteral && node.operator === SyntaxKind.PlusToken) {
return getFreshTypeOfLiteralType(getLiteralType(+(<LiteralExpression>node.operand).text));
}
switch (node.operator) {
case SyntaxKind.PlusToken:
case SyntaxKind.MinusToken: