Skip to content

iterating an enum is now an error #33123

@gpra

Description

@gpra

Iterating a string enum in strict mode is not allowed since 3.6.2. Is this a breaking change or a bug?

Sample code:

// sample.ts
// compile with: `tsc --strict sample.ts`
enum DAYS { Monday = 'monday', Tuesday = 'tuesday' }

for (const a in DAYS) {
  const x = DAYS[a];  // <- This is now an error
  console.log(x);
}

tsc --strict sample.ts

TSC 3.5.2: Compiles OK

TSC 3.6.2: reports an error:
error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'typeof DAYS'.

Metadata

Metadata

Assignees

Labels

RescheduledThis issue was previously scheduled to an earlier milestoneWorking as IntendedThe behavior described is the intended behavior; this is not a bug

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions