Skip to content

Issue with mapped types and enums #17288

Closed
@blocka

Description

@blocka

TypeScript Version: 2.4.1 /

Code

enum Things {
	ONE = "one",
	TWO = "two"
}

type ThingMap = { [TKey in Things]: any };

const thingMap: ThingMap = {
	one: null,
	two: null
};

function setThing(thing: Things, something: any) {
	thingMap[thing] = something;
}

Expected behavior:
Just like I can do thingMap[Things.ONE] = 'blah' without any errors, this should not throw an error.
Actual behavior:
src/test.ts(14,2): error TS7017: Element implicitly has an 'any' type because type 'ThingMap' 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