Third parameter of set
is not included in type definition
#2734
-
Bug DescriptionIn the snippet below, the If you just ignore the TS error and run the code anyway, the code does work and produces the expected result in the Redux dev tools (an action of type type TestState = {
testing: boolean;
setTesting: (value: boolean) => void;
}
export const createTestState: StateCreator<TestState, [], [], TestState> = (
set,
_get,
_store
) => ({
testing: false,
setTesting(value: boolean) {
set({ testing: value }, undefined, { type: 'set/testing' })
}
});
export const createUserStore = () =>
createStore<TestState>()(
devtools((set, get, store) => createTestState(set, get, store), {
name: 'Testing'
})
); WorkaroundAs a workaround, we did this horrible thing below, to cast export const createTestState: StateCreator<TestState, [], [], TestState> = (
_set,
_get,
_store
) => {
const set = _set as ((...params: [...Parameters<typeof _set>, { type: unknown }?]) => ReturnType<typeof _set>);
return {
testing: false,
setTesting(value: boolean) {
set({ testing: value }, undefined, { type: 'set/testing' })
}
}
} Reproduction Link |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
@ncksllvn here you go -> instead of this StateCreator<TestState, [], [], TestState> should be this StateCreator<TestState, [['zustand/devtools', never]], [], TestState> |
Beta Was this translation helpful? Give feedback.
-
Wow sorry I missed that in the docs. Thanks @dbritto-dev ! |
Beta Was this translation helpful? Give feedback.
@ncksllvn here you go ->
instead of this
should be this