I'm trying to make a generic type which will make keys of the given type required if they are a certain type. Rest of the keys should be optional or omitted.
Consider the following example:
interface Foo {
prop1: string;
prop2: boolean;
prop3: boolean;
prop4: number;
}
/*
* Make all the keys with boolean type required
* Rest of the keys can be optional or omitted
*/
const foo: BooleanOnlyFields<Foo> = {
prop2: true,
// Should show error that prop3 is required because it's boolean type
}
Is it possible to implement something like BooleanOnlyFields
in Typescript?