I have the following key-value pair and it is being used for a filtering system. When we apply a filter, we could merge it with all the current ones, or just apply it with resetting the previous.
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;
};
Then I have the following prototype of a function:
const apply = (filter: Filter) => void
When we use it:
// name: PossibleFilterKeys,
// value: string,
apply({[name]: value})
It triggers: 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
I want to apply a filter, its key could be one of the PossibleFilterKeys type, but it throws the error above.
Why does this happen?
[key in PossibleFilterKeys]?: stringbut we also can use the Partial utility:apply: (filter: Partial<Filter>) => void