0

I want to define a generic type KeyOfType<T, U> to be the (widest) type K satisfying T[K] extends U.

For example:

interface Foo {
    a: number
    b: number
    c: string
    d: 1 | 2
    e: number | string
}

In this case, KeyOfType<Foo, number> should be 'a' | 'b' | 'd', since these are the keys of Foo whose values are assignable to number.

Is this possible?

Nicholas Weston
  • 609
  • 3
  • 11

0 Answers0