Skip to content

Commit 75a812b

Browse files
a-tarasyukRyanCavanaugh
authored andcommitted
add new message - TS1258 (microsoft#30704)
1 parent fed46ea commit 75a812b

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31462,7 +31462,7 @@ namespace ts {
3146231462
}
3146331463

3146431464
if (node.exclamationToken && (node.parent.parent.kind !== SyntaxKind.VariableStatement || !node.type || node.initializer || node.flags & NodeFlags.Ambient)) {
31465-
return grammarErrorOnNode(node.exclamationToken, Diagnostics.A_definite_assignment_assertion_is_not_permitted_in_this_context);
31465+
return grammarErrorOnNode(node.exclamationToken, Diagnostics.Definite_assignment_assertions_can_only_be_used_along_with_a_type_annotation);
3146631466
}
3146731467

3146831468
if (compilerOptions.module !== ModuleKind.ES2015 && compilerOptions.module !== ModuleKind.ESNext && compilerOptions.module !== ModuleKind.System && !compilerOptions.noEmit &&

src/compiler/diagnosticMessages.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,10 @@
847847
"category": "Error",
848848
"code": 1257
849849
},
850+
"Definite assignment assertions can only be used along with a type annotation.": {
851+
"category": "Error",
852+
"code": 1258
853+
},
850854
"'with' statements are not allowed in an async function block.": {
851855
"category": "Error",
852856
"code": 1300

tests/baselines/reference/definiteAssignmentAssertions.errors.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(21,6): error
44
tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(22,13): error TS1255: A definite assignment assertion '!' is not permitted in this context.
55
tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(28,6): error TS1255: A definite assignment assertion '!' is not permitted in this context.
66
tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(34,15): error TS1255: A definite assignment assertion '!' is not permitted in this context.
7-
tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(68,10): error TS1255: A definite assignment assertion '!' is not permitted in this context.
8-
tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(69,10): error TS1255: A definite assignment assertion '!' is not permitted in this context.
9-
tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(70,10): error TS1255: A definite assignment assertion '!' is not permitted in this context.
10-
tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(75,15): error TS1255: A definite assignment assertion '!' is not permitted in this context.
11-
tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(76,15): error TS1255: A definite assignment assertion '!' is not permitted in this context.
7+
tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(68,10): error TS1258: Definite assignment assertions can only be used along with a type annotation.
8+
tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(69,10): error TS1258: Definite assignment assertions can only be used along with a type annotation.
9+
tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(70,10): error TS1258: Definite assignment assertions can only be used along with a type annotation.
10+
tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(75,15): error TS1258: Definite assignment assertions can only be used along with a type annotation.
11+
tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(76,15): error TS1258: Definite assignment assertions can only be used along with a type annotation.
1212

1313

1414
==== tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts (11 errors) ====
@@ -93,21 +93,21 @@ tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(76,15): erro
9393
function f4() {
9494
let a!;
9595
~
96-
!!! error TS1255: A definite assignment assertion '!' is not permitted in this context.
96+
!!! error TS1258: Definite assignment assertions can only be used along with a type annotation.
9797
let b! = 1;
9898
~
99-
!!! error TS1255: A definite assignment assertion '!' is not permitted in this context.
99+
!!! error TS1258: Definite assignment assertions can only be used along with a type annotation.
100100
let c!: number = 1;
101101
~
102-
!!! error TS1255: A definite assignment assertion '!' is not permitted in this context.
102+
!!! error TS1258: Definite assignment assertions can only be used along with a type annotation.
103103
}
104104

105105
// Definite assignment assertion not permitted in ambient context
106106

107107
declare let v1!: number;
108108
~
109-
!!! error TS1255: A definite assignment assertion '!' is not permitted in this context.
109+
!!! error TS1258: Definite assignment assertions can only be used along with a type annotation.
110110
declare var v2!: number;
111111
~
112-
!!! error TS1255: A definite assignment assertion '!' is not permitted in this context.
112+
!!! error TS1258: Definite assignment assertions can only be used along with a type annotation.
113113

0 commit comments

Comments
 (0)