Here is a key-value pair used for a filtering system. The filter can be merged with current filters or applied by resetting the previous ones.
type MINE = "mine"
type BOOKMARKED = "bookmarked"
type TEXT_QUERY = "textQuery"
type JobType = "type"
export type PossibleFilterKeys = MINE | BOOKMARKED | TEXT_QUERY | JobType
type Filter = {
[key in PossibleFilterKeys]: string;
};
Next, we have a function prototype:
const apply = (filter: Filter) => void
When using it:
// name: PossibleFilterKeys,
// value: string,
apply({[name]: value})
This triggers the error:
TS2345: Argument of type '{ [x: string]: string; }' is not assignable to parameter of type 'Filter'. Type '{ [x: string]: string; }' is missing the following properties from type 'Filter': mine, bookmarked, textQuery, type
It's supposed to accept a filter with a key from PossibleFilterKeys
type, so why does this error occur?