Skip to content

for(...in...) with mapped types cannot see index type (noImplicitAny) #14451

Closed
@jameswilddev

Description

@jameswilddev

TypeScript Version: 2.2.1
Code

// noImplicitAny must be enabled.

type Options = "A" | "B" | "C"
const MappedOptions: {[option in Options]: number } = {
    A: 2,
    B: 3,
    C: 4
}

for (const key in MappedOptions) {
    alert(MappedOptions[key])
}

Expected behavior:
This compiles, as the index type of MappedOptions is Options.

Actual behavior:
A compile-time error occurs as MappedOptions has no index signature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions