In TypeScript, how to get the keys of an object type whose values are of a given type?

This can be done with conditional types and indexed access types, like this: type KeysMatching<T, V> = {[K in keyof T]-?: T[K] extends V ? K : never}[keyof T]; and then you pull out the keys whose properties match string like this: const key: KeysMatching<Thing, string> = ‘other’; // ERROR! // ‘”other”‘ is not assignable … Read more