Typescript: Allows to mutate `const` with non-null assertion

Created on 10 Feb 2018  路  5Comments  路  Source: microsoft/TypeScript

TypeScript Version: 2.8.0-dev.20180209

Code

declare const x: number | undefined;
x!++;

Expected behavior:

src/a.ts(2,2): error TS2540: Cannot assign to 'x' because it is a constant or a read-only property.

Actual behavior:

No error.

Bug Fixed help wanted

Most helpful comment

Sorry. It's been a long week.

All 5 comments

But you said it was a constant?

The expected behavior is an error. The actual behavior is no error. For x: number and x++ there is correctly an error.

Sorry. It's been a long week.

thanks @jack-williams!

No problem!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

blendsdk picture blendsdk  路  3Comments

uber5001 picture uber5001  路  3Comments

kyasbal-1994 picture kyasbal-1994  路  3Comments

Roam-Cooper picture Roam-Cooper  路  3Comments

remojansen picture remojansen  路  3Comments