type KeysMatching<T, V> = keyof { [P in keyof T as T[P] extends V ? P : never]: any } & keyof T type Example = { foo: number; bar?: string; baz?: number } type T1 = KeysMatching<Example, number> // 'foo' | 'baz' type T2 = KeysMatching<Example, string> // 'bar'

