In redux toolkit, I have a slice that is mostly string arrays, and I want an action that pushes a string onto one of the arrays. The action should take the key of the array to push onto, and the string to push.
Here is how I've typed it:
const initialState = {
gameModes: [] as string[],
contestTypes: [] as string[],
entryFee: {
max: 10000,
min: 0,
},
entryTypes: [] as string[],
advancedFilters: [] as string[],
};
type ContestFilterSliceType = typeof initialState;
type ContestFilterKey = keyof ContestFilterKey;
const contestFilterSlice = createSlice({
name: "constestFilter",
initialState,
reducers: {
addFilter(
state,
action: PayloadAction<{ key: Omit<ContestFilterKey, "entryFee">; filter: string }>
) {
const { filter, key } = action.payload;
state[key].push(filter);
},
},
});
When I hover over type ContestFilterKey = keyof ContestFilterKey;, I see that the type is, correctly, a list of the keys of the initialState.
However, when I hover over key: Omit<ContestFilterKey, "entryFee">, I get this:
key: Pick<"gameModes" | "contestTypes" | "entryFee" | "entryTypes" | "advancedFilters", number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | ... 40 more ... | "replaceAll">
It appears that the latter includes a whole bunch of prototype methods. Of Array? Of Object? Unclear.
I would expect Omit<ContestFilterKey, "entryFee"> to simply be: "gameModes" | "contestTypes" | "entryTypes" | "advancedFilters"
What am I missing here?