I am looking for a specific type:
interface Filter<P extends object> {
label: string;
options: FilterOption[];
key: StringArrayKeyOf<P>;
}
The definition of StringArrayKeyOf
is as follows:
type StringArrayKeyOf<T extends object> = Exclude<{ [K in keyof T]: T[K] extends string[] ? K : never; }[keyof T], undefined>;
However, when I attempt to use it in this way:
const stateFilters: Filter<GiftOrderHistoryParams> = {
label: 'State',
options: stateOptions,
key: 'state',
};
Where GiftOrderHistoryParams
has the following structure:
interface GiftOrderHistoryParams {
...
state?: string[];
}
An error is thrown regarding the key
property:
Type string is not assignable to type never
The expected type for the key
should be a string that indexes type P
where the value is of type string[]