Closed
Description
I don't recognize any examples of this in the docs. Can we map to a type that holds the return types of key-indexed functions? Is there a syntax for that?
var ex = {
One<S>(x : S) { return x; }
Two<T>(y : T) { return "foo"; }
Three() { return false; }
}
// Bad because all return types would have to be the same `T`
type BadMappedOutputs<T, O extends { [k : string] : () => T }> = {
[K in keyof O] : T
}
// Something like this?
type MappedOutputs<O> = {
<T>[K in keyof O where O[K] extends () => T] : T
}
var baz = MappedOutputs<typeof ex>;
baz.One; // any
baz.Two; // string
baz.Three; // boolean