-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Open
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
It is a fairly common pattern to create a set of generic components, and then to use the generic component type within the system. Currently, typescript has an issue handling cases where some values of a generic component depend on others.
TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx)
2.4
Code
let index = {
a: {
arg: 'a',
fn: (a: string) => {a.toUpperCase()}
},
b: {
arg: 1,
fn: (b: number) => {b + 1}
}
}
let runFn= <K extends keyof (typeof index)>(key: K) => {
let i = index[key]
let arg = i.arg
let fn = i.fn
fn(arg) // Error: compiler doesn't understand that fn and arg will match
}
Expected behavior:
No error, since we know that arg
and fn
are pulled off of the same map entry.
Actual behavior:
Error: cannot invoke expression whose type lacks a call signature
sebastian-fredriksson-bernholtz, kpozin, patmigliaccio and ashclarkegoliath-backend
Metadata
Metadata
Assignees
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript