Let's say I have an interface like this:
interface SomeInterface {
field1: string;
field2: number;
field3: string;
field4: SomeOtherType;
}
I'd like to have a type that can extract all the keys who's values are a specific type:
type ExtractFieldsOfType<Obj extends {}, Type> = // implementation
ExtractFieldsOfType<SomeInterface, string> // "field1" | "field3"
ExtractFieldsOfType<SomeInterface, number> // "field2"
ExtractFieldsOfType<SomeInterface, SomeOtherType> // "field4"
Is it possible to write something like this? I'm writing a function that operates on an object by key name, but it should only allow keys with specific values. So it'd be nice to express that through the type system.