Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38003,7 +38003,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
const exprType = checkExpression(expression, checkMode);
if (isConstTypeReference(type)) {
if (!isValidConstAssertionArgument(expression)) {
error(expression, Diagnostics.A_const_assertions_can_only_be_applied_to_references_to_enum_members_or_string_number_boolean_array_or_object_literals);
error(expression, Diagnostics.A_const_assertion_can_only_be_applied_to_references_to_enum_members_or_string_number_boolean_array_or_object_literals);
}
return getRegularTypeOfLiteralType(exprType);
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,7 @@
"category": "Error",
"code": 1354
},
"A 'const' assertions can only be applied to references to enum members, or string, number, boolean, array, or object literals.": {
"A 'const' assertion can only be applied to references to enum members, or string, number, boolean, array, or object literals.": {
"category": "Error",
"code": 1355
},
Expand Down
12 changes: 6 additions & 6 deletions tests/baselines/reference/constAssertions.errors.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
constAssertions.ts(44,32): error TS2540: Cannot assign to 'x' because it is a read-only property.
constAssertions.ts(61,10): error TS1355: A 'const' assertions can only be applied to references to enum members, or string, number, boolean, array, or object literals.
constAssertions.ts(62,10): error TS1355: A 'const' assertions can only be applied to references to enum members, or string, number, boolean, array, or object literals.
constAssertions.ts(63,10): error TS1355: A 'const' assertions can only be applied to references to enum members, or string, number, boolean, array, or object literals.
constAssertions.ts(61,10): error TS1355: A 'const' assertion can only be applied to references to enum members, or string, number, boolean, array, or object literals.
constAssertions.ts(62,10): error TS1355: A 'const' assertion can only be applied to references to enum members, or string, number, boolean, array, or object literals.
constAssertions.ts(63,10): error TS1355: A 'const' assertion can only be applied to references to enum members, or string, number, boolean, array, or object literals.
constAssertions.ts(118,3): error TS2322: Type '3' is not assignable to type '2'.


Expand Down Expand Up @@ -70,13 +70,13 @@ constAssertions.ts(118,3): error TS2322: Type '3' is not assignable to type '2'.

let e1 = v1 as const; // Error
~~
!!! error TS1355: A 'const' assertions can only be applied to references to enum members, or string, number, boolean, array, or object literals.
!!! error TS1355: A 'const' assertion can only be applied to references to enum members, or string, number, boolean, array, or object literals.
let e2 = (true ? 1 : 0) as const; // Error
~~~~~~~~~~~~~~
!!! error TS1355: A 'const' assertions can only be applied to references to enum members, or string, number, boolean, array, or object literals.
!!! error TS1355: A 'const' assertion can only be applied to references to enum members, or string, number, boolean, array, or object literals.
let e3 = id(1) as const; // Error
~~~~~
!!! error TS1355: A 'const' assertions can only be applied to references to enum members, or string, number, boolean, array, or object literals.
!!! error TS1355: A 'const' assertion can only be applied to references to enum members, or string, number, boolean, array, or object literals.

let t1 = 'foo' as const;
let t2 = 'bar' as const;
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/constantEnumAssert.errors.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
constantEnumAssert.ts(49,20): error TS1355: A 'const' assertions can only be applied to references to enum members, or string, number, boolean, array, or object literals.
constantEnumAssert.ts(49,20): error TS1355: A 'const' assertion can only be applied to references to enum members, or string, number, boolean, array, or object literals.


==== constantEnumAssert.ts (1 errors) ====
Expand Down Expand Up @@ -52,5 +52,5 @@ constantEnumAssert.ts(49,20): error TS1355: A 'const' assertions can only be app

const foo12 = { a: E5.a as const }
~~~~
!!! error TS1355: A 'const' assertions can only be applied to references to enum members, or string, number, boolean, array, or object literals.
!!! error TS1355: A 'const' assertion can only be applied to references to enum members, or string, number, boolean, array, or object literals.

Loading