#How to omit the second generic parameter definition?

4 messages · Page 1 of 1 (latest)

wraith grove
gray condorBOT
#
YiiSh#8749

Preview:ts ... const t1 = myFunc2<A, "a">("a") // type: string | null, How to omit the second generic parameter definition? ...

quick hazel
#

you can't have partial inferment in a generic function

lone meteor
#

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```