The TypeScript language comes with a built-in Pick
type, which is defined as follows:
type Pick<T, K extends keyof T> = {
[P in K]: T[P];
};
If you were to create a custom PickByValue
type, how would you implement it to achieve the following functionality:
type Test = {
includeMe: 'a' as 'a',
andMe: 'a' as 'a',
butNotMe: 'b' as 'b',
orMe: 'b' as 'b'
};
type IncludedKeys = keyof PickByValue<Test, 'a'>;
// IncludedKeys = 'includeMe' | 'andMe'