question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[v3.5.2] Type error when using devtools and persist in TypeScript

See original GitHub issue

Test 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

zustand-type-error

CodeSandbox

https://codesandbox.io/s/elegant-flower-s0e9c?file=/src/App.tsx

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
TkDodocommented, Jun 14, 2021

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.

1reaction
TkDodocommented, Jun 20, 2021

@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 👍

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found