-
Couldn't load subscription status.
- Fork 13.1k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
Why does this code work:
type KeyTypes = "a" | "b"
let MyThingy: { [key in KeyTypes]: string[] };
function addToMyThingy(key: "a" | "b") {
MyThingy[key].push("a");
}
And this code fail?
type KeyTypes = "a" | "b"
let MyThingy: { [key in KeyTypes]: string[] };
function addToMyThingy<S extends KeyTypes>(key: S) {
MyThingy[key].push("a"); // Error: Property 'push' does not exist on type '{ a: string[]; b: string[]; }[S]'.
}
Unless I've misunderstood S extends KeyTypes, all I've done is constrained key to be "a" or "b" with my type parameter.
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue