[v3.5.2] Type error when using devtools and persist in TypeScript
See original GitHub issueTest code
import create from 'zustand';
import { devtools, persist } from 'zustand/middleware';
interface TestState {
t1: string;
t2: number;
setT1: (t: string) => void;
[key: string]: any;
}
const useTest = create<TestState>(
devtools(
persist(
(set) => ({
t1: null,
t2: null,
setT1: (n) => {
set({
t1: n,
});
},
}),
{
name: 'zustand-state-test',
getStorage: () => localStorage,
},
),
),
);
export default useTest;
What happens?
zustand: 3.4.2
no type error
zustand: 3.5.2
show some type error
persist use SetState, but devtools use NamedSet.
Screenshot

CodeSandbox
https://codesandbox.io/s/elegant-flower-s0e9c?file=/src/App.tsx
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
TS issue with the set function when using devtools (with older ...
I'm having a problem when using zustand with devtools in my next.js project. ... Type error: Expected 3-4 arguments, but got 1.
Read more >Cannot find type definition file for 'redux-logger' - Stack Overflow
This error most likely means that the typeRoots mechanism found a directory that appeared to represent a package named @types/redux-logger ...
Read more >Spring Boot Reference Documentation
Try the How-to documents. They provide solutions to the most common questions. Learn the Spring basics. Spring Boot builds on many other Spring...
Read more >What's New In DevTools (Chrome 65)
New features coming to DevTools in Chrome 65 include: Local Overrides; New accessibility tools; The Changes tab; New SEO and performance audits ...
Read more >'router' cannot be used as a jsx component. its instance type ...
I am using react-redux with redux-persist in a react js application with TypeScript. store.jsx. import {applyMiddleware, createStore} from 'redux'; ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I put the example code in a codesandbox: https://codesandbox.io/s/elegant-flower-s0e9c?file=/src/App.tsx
If you put it in the issue description, any linked PR will automatically deploy it, thanks.
I also tested it on #428 but the error remains the same. Need to look closer into it but might take some time.
@FranciscoMendes10866 I tested your example with #441 and it works there.
also, the initial sandbox from @onlyling seems to work with #441 , so it looks really promising 👍