fix(41965): fix error in definite assignment assertion context (#41989)

This commit is contained in:
Oleksandr T 2020-12-30 21:45:18 +02:00 committed by GitHub
parent dfe23421ba
commit e108257fb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 6 deletions

View File

@ -40134,7 +40134,9 @@ namespace ts {
if (node.exclamationToken && (node.parent.parent.kind !== SyntaxKind.VariableStatement || !node.type || node.initializer || node.flags & NodeFlags.Ambient)) {
const message = node.initializer
? Diagnostics.Declarations_with_initializers_cannot_also_have_definite_assignment_assertions
: Diagnostics.Declarations_with_definite_assignment_assertions_must_also_have_type_annotations;
: !node.type
? Diagnostics.Declarations_with_definite_assignment_assertions_must_also_have_type_annotations
: Diagnostics.A_definite_assignment_assertion_is_not_permitted_in_this_context;
return grammarErrorOnNode(node.exclamationToken, message);
}

View File

@ -9,11 +9,12 @@ tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(35,15): erro
tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(69,10): error TS1264: Declarations with definite assignment assertions must also have type annotations.
tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(70,10): error TS1263: Declarations with initializers cannot also have definite assignment assertions.
tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(71,10): error TS1263: Declarations with initializers cannot also have definite assignment assertions.
tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(76,15): error TS1264: Declarations with definite assignment assertions must also have type annotations.
tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(77,15): error TS1264: Declarations with definite assignment assertions must also have type annotations.
tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(76,15): error TS1255: A definite assignment assertion '!' is not permitted in this context.
tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(77,15): error TS1255: A definite assignment assertion '!' is not permitted in this context.
tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(80,7): error TS1255: A definite assignment assertion '!' is not permitted in this context.
==== tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts (13 errors) ====
==== tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts (14 errors) ====
// Suppress strict property initialization check
class C1 {
@ -113,8 +114,14 @@ tests/cases/conformance/controlFlow/definiteAssignmentAssertions.ts(77,15): erro
declare let v1!: number;
~
!!! error TS1264: Declarations with definite assignment assertions must also have type annotations.
!!! error TS1255: A definite assignment assertion '!' is not permitted in this context.
declare var v2!: number;
~
!!! error TS1264: Declarations with definite assignment assertions must also have type annotations.
!!! error TS1255: A definite assignment assertion '!' is not permitted in this context.
declare namespace foo {
var v!: number;
~
!!! error TS1255: A definite assignment assertion '!' is not permitted in this context.
}

View File

@ -76,6 +76,10 @@ function f4() {
declare let v1!: number;
declare var v2!: number;
declare namespace foo {
var v!: number;
}
//// [definiteAssignmentAssertions.js]
@ -166,3 +170,6 @@ declare function f3(): void;
declare function f4(): void;
declare let v1: number;
declare var v2: number;
declare namespace foo {
var v: number;
}

View File

@ -147,3 +147,10 @@ declare let v1!: number;
declare var v2!: number;
>v2 : Symbol(v2, Decl(definiteAssignmentAssertions.ts, 76, 11))
declare namespace foo {
>foo : Symbol(foo, Decl(definiteAssignmentAssertions.ts, 76, 24))
var v!: number;
>v : Symbol(v, Decl(definiteAssignmentAssertions.ts, 79, 4))
}

View File

@ -158,3 +158,10 @@ declare let v1!: number;
declare var v2!: number;
>v2 : number
declare namespace foo {
>foo : typeof foo
var v!: number;
>v : number
}

View File

@ -78,3 +78,7 @@ function f4() {
declare let v1!: number;
declare var v2!: number;
declare namespace foo {
var v!: number;
}