mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
allow literan enum const assertions (#30700)
* allow literan enum const assertions * update desc
This commit is contained in:
committed by
Ryan Cavanaugh
parent
b0100100a1
commit
bc46c770bf
@@ -21973,6 +21973,13 @@ namespace ts {
|
||||
const arg = (<PrefixUnaryExpression>node).operand;
|
||||
return op === SyntaxKind.MinusToken && (arg.kind === SyntaxKind.NumericLiteral || arg.kind === SyntaxKind.BigIntLiteral) ||
|
||||
op === SyntaxKind.PlusToken && arg.kind === SyntaxKind.NumericLiteral;
|
||||
case SyntaxKind.PropertyAccessExpression:
|
||||
case SyntaxKind.ElementAccessExpression:
|
||||
const expr = (<PropertyAccessExpression | ElementAccessExpression>node).expression;
|
||||
if (isIdentifier(expr)) {
|
||||
const symbol = getSymbolAtLocation(expr);
|
||||
return !!(symbol && (symbol.flags & SymbolFlags.Enum) && getEnumKind(symbol) === EnumKind.Literal);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -21981,7 +21988,7 @@ namespace ts {
|
||||
let exprType = checkExpression(expression, checkMode);
|
||||
if (isConstTypeReference(type)) {
|
||||
if (!isValidConstAssertionArgument(expression)) {
|
||||
error(expression, Diagnostics.A_const_assertion_can_only_be_applied_to_a_string_number_boolean_array_or_object_literal);
|
||||
error(expression, Diagnostics.A_const_assertions_can_only_be_applied_to_references_to_enum_members_or_string_number_boolean_array_or_object_literals);
|
||||
}
|
||||
return getRegularTypeOfLiteralType(exprType);
|
||||
}
|
||||
|
||||
@@ -1031,7 +1031,7 @@
|
||||
"category": "Error",
|
||||
"code": 1354
|
||||
},
|
||||
"A 'const' assertion can only be applied to a string, number, boolean, array, or object literal.": {
|
||||
"A 'const' assertions can only be applied to references to enum members, or string, number, boolean, array, or object literals.": {
|
||||
"category": "Error",
|
||||
"code": 1355
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user