Fix #21848: Allows to mutate const with non-null assertion (#21873)

This commit is contained in:
jack-williams 2018-02-12 18:57:59 +00:00 committed by Mohamed Hegazy
parent ddf206b184
commit 67984c720e
6 changed files with 46 additions and 0 deletions

View file

@ -1754,6 +1754,7 @@ namespace ts {
case SyntaxKind.ParenthesizedExpression:
case SyntaxKind.ArrayLiteralExpression:
case SyntaxKind.SpreadElement:
case SyntaxKind.NonNullExpression:
node = parent;
break;
case SyntaxKind.ShorthandPropertyAssignment:

View file

@ -0,0 +1,11 @@
tests/cases/compiler/constWithNonNull.ts(4,1): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.
==== tests/cases/compiler/constWithNonNull.ts (1 errors) ====
// Fixes #21848
declare const x: number | undefined;
x!++;
~
!!! error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.

View file

@ -0,0 +1,10 @@
//// [constWithNonNull.ts]
// Fixes #21848
declare const x: number | undefined;
x!++;
//// [constWithNonNull.js]
// Fixes #21848
x++;

View file

@ -0,0 +1,9 @@
=== tests/cases/compiler/constWithNonNull.ts ===
// Fixes #21848
declare const x: number | undefined;
>x : Symbol(x, Decl(constWithNonNull.ts, 2, 13))
x!++;
>x : Symbol(x, Decl(constWithNonNull.ts, 2, 13))

View file

@ -0,0 +1,11 @@
=== tests/cases/compiler/constWithNonNull.ts ===
// Fixes #21848
declare const x: number | undefined;
>x : number
x!++;
>x!++ : number
>x! : any
>x : any

View file

@ -0,0 +1,4 @@
// Fixes #21848
declare const x: number | undefined;
x!++;