Skip to content

Bugs with enum (import and typing) #3507

Closed
@loucyx

Description

@loucyx

When I import a module that has an enum and then I pass a string variable as index, with the noImplicitAny flag set to true, I get an error of implicit any in the index signature.

Examples:

This works but it has an unwanted behavior detailed in the comment:

enum Foobar {
    "foo",
    "bar"
}

var consoleFoobar = (index: string) => {
    // output is of type any. It should be number if the index is string and string if the index is number
    var output = Foobar[index];
    console.log(output);
}

This trows an error:

// a-module.ts
export enum Foobar {
    "foo",
    "bar"
}

// app.ts
import { Foobar } from "./a-module";

var consoleFoobar = (index: string) => {
    var output = Foobar[index]; // Error: Index signature of object type implicitly has an 'any' type.
    console.log(output);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    By DesignDeprecated - use "Working as Intended" or "Design Limitation" instead

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions