Typescript: Mis-parsing of variables named `enum`

Created on 30 May 2018  路  4Comments  路  Source: microsoft/TypeScript

TypeScript Version: 2.8.3

Search Terms:

  • enum variable name

Code

interface Foo {
    enum: string;
}

function bar({ enum }: Foo) {
    if (enum) {
        //
    }
}

Expected behavior:

Code compiles without issue.

Actual behavior:

Error at 5: Enum declarations can only merge with namespace or other enum declarations.
Error at 5: ':' expected.
Error at 6: Enum declarations can only merge with namespace or other enum declarations.
Error at 6: Expression expected.
Error at 6: Identifier expected.

Playground Link:
Playground

Bug help wanted

Most helpful comment

Illegal code but we should issue a better parse error here

All 4 comments

function bar({ enum }) {} doesn't work in the node.js console either.

Illegal code but we should issue a better parse error here

I was scratching my head, because the following is valid:

function bar({ enum: e }) {}

But then I remembered that enum is a reserved word in ECMAScript these days...

related #11648

Was this page helpful?
0 / 5 - 0 ratings

Related issues

manekinekko picture manekinekko  路  3Comments

kyasbal-1994 picture kyasbal-1994  路  3Comments

Antony-Jones picture Antony-Jones  路  3Comments

DanielRosenwasser picture DanielRosenwasser  路  3Comments

zhuravlikjb picture zhuravlikjb  路  3Comments