-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
Bug Report
🔎 Search Terms
index type generic
🕗 Version & Regression Information
4.9.0-dev.20221025
⏯ Playground Link
Playground link with relevant code
💻 Code
interface Foo {
a: number[]
b: string[]
}
declare const foo: Foo
const setValue = <T extends keyof Foo>(key: T, value: Foo[T][number]) => {
foo[key] = [value]
}🙁 Actual behavior
Type '(string | number)[]' is not assignable to type 'Foo[T]'.
Type '(string | number)[]' is not assignable to type 'number[] & string[]'.
Type '(string | number)[]' is not assignable to type 'number[]'.
Type 'string | number' is not assignable to type 'number'.
Type 'string' is not assignable to type 'number'.
🙂 Expected behavior
no error, since it works when the type of value is Foo[T]:
const setValue = <T extends keyof Foo>(key: T, value: Foo[T]) => {
foo[key] = value
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created