#How to omit the second generic parameter definition?
4 messages · Page 1 of 1 (latest)
Preview:ts ... const t1 = myFunc2<A, "a">("a") // type: string | null, How to omit the second generic parameter definition? ...
you can't have partial inferment in a generic function
there is a workaround, but it's not pretty
export function myFunc3<T extends object>(): <K extends keyof T>(key: K) => T[K] | null {
return <K extends keyof T>(key: K) => null;
}
const t1 = myFunc3<A>()("a") // type: string | null```