Skip to content

bug(parser): missing/unsupported enum syntax in typescript #4449

@armano2

Description

@armano2

Parser fails if computed property is provided as key of enum, this synatx should be allowed only for computed properties with string literal value or template literal without arguments.

// should work
enum Foo { ['baz'] }             // ❌ currently fails
enum Foo { [`baz`] }             // ❌ currently fails
enum Foo { ['baz'] = 2 }         // ❌ currently fails
enum Foo { [`baz`] = 2 }         // ❌ currently fails
enum Foo { 'baz' }               // 👍 work fine
enum Foo { baz }                 // 👍 work fine
enum Foo { 'baz' = 2 }           // 👍 work fine
enum Foo { baz = 2 }             // 👍 work fine

// should fail
enum Foo { [foo] }               // Computed property names are not allowed in enums
enum Foo { [1] }                 // An enum member cannot have a numeric name.
enum Foo { [`test${foo}`] }      // Computed property names are not allowed in enums.
enum Foo { `baz` = 2 }           // Enum member expected.
enum Foo { ['baz' + 'baz'] }     // Computed property names are not allowed in enums.

ref microsoft/TypeScript#42468

Metadata

Metadata

Assignees

Labels

A-parserArea - ParserC-bugCategory - Bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions