I would like to declare a type that requires all the keys of a given type T to be included in an array, e.g.:
checkKeys<T>(arr: Array<keyof T>): void {
// do something
}
interface MyType {
id: string;
value: number;
}
Currently if a call checkKeys<MyType>, TS will consider the value passed as valid if it contains any key of MyType (id | value):
checkKeys<MyType>(['id', 'value']); // valid
checkKeys<MyType>(['id']); // valid
checkKeys<MyType>(['id', 'values']); // invalid
Is it possible to require that all keys are specified in the array?