devtools extension breaks types #3510
Replies: 2 comments 5 replies
-
|
Can anyone look into it? |
Beta Was this translation helpful? Give feedback.
-
|
This is a known behavior when combining TypeScript with Zustand's curried When you use the curried creator How to resolve:The recommended approach in Zustand's TypeScript guide is to use the non-curried store creator syntax and explicitly define the middleware mutators as the second type parameter: import { createStore } from 'zustand/vanilla';
import { devtools } from "zustand/middleware";
interface Store {
attr: number;
setAttr: () => void;
}
// Pass the devtools mutator tuple as the second generic parameter
export const store = createStore<Store, [["zustand/devtools", never]]>(
devtools((set) => ({
attr: 'string', // Error: Type 'string' is not assignable to type 'number'
setAttr: false, // Error: Type 'boolean' is not assignable to type '() => void'
}))
);Why this works:By specifying |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Bug Description
devtoolsextension breaks type check, allows any store type.Works fine without the middleware
Reproduction Link
https://www.typescriptlang.org/play/?#code/FASwtgDg9gTgLgAgN4IMYwKYEM4YMpywYIC+CAZjFGAgOQBeArgM5xYB2AJgPQBuHIADaCstANyhIsRCk4ZehKIOakKVGgCImrDjzAhOnQRgDuWTBomh2uGOSypiBIsmAIEOODABcCdozAAIwwYCXdmDDgAQTgvXwAKAEoEAF4APgReKAMJEmBgdGxcZ0wAHhKMNKT4uQUoJWZ4gH0IxHSEeKQ3BG5uBAABOGYAWgwADwgMVDhRmCoYBGHhhAAVAAsQ4mY1qEZBTgRghBD5hA3MReWAIUZEOHPiEBV2KGO52G7PHzpWGBB2ADmtAANN1egMhqMJlMZidYJdVg8ENtdvtDsQ4QskUsEDc7kinn5Xpjuq0YnEKFhlBhQSREvSrIUcPhCGUKlVEs1WqkMp0wX1BiNxpNprNTjj1ptkTs9gcjpizlKcVFhAgAfVOJ9Yt9aL9-kDQe5wYKoSLYe8FhKkSjZei3qdscsVYI1RrSZFyd97NTaQzgEA
Beta Was this translation helpful? Give feedback.
All reactions