Export WithImmer
type
#1454
Replies: 5 comments 5 replies
-
It's actually intentional. We consider |
Beta Was this translation helpful? Give feedback.
-
Reopening this discussion, because it's still relevant. Using the solution from #930 isn't ideal, because it requires every file that imports the mutated type to also import Immer and Devtools, otherwise, the type appear as never. An example of this problem can be seen here. Exporting the intermediary types such as WithImmer and WithDevtools fixes these problems all together and makes store typing a lot easier. So the code would look like this: export type BluefireStore = UseBoundStore<WithImmer<WithDevtools<StoreApi<BluefireState>>>>; |
Beta Was this translation helpful? Give feedback.
-
Hey, as some have already stated, exporting Besides that, the type does not seem internal, as it is something we, as the end users of the library have to deal with. |
Beta Was this translation helpful? Give feedback.
-
I'll let @dai-shi decide whether to export the internal types or not (I personally am inclined to not exporting too). I'm not sure how you would solve this problem, one solution that I think might work is something like this... // @file zustand/middleware/immer.ts
import type { Draft as _Draft } from "immer"
type Draft<T> = _Draft<T>
// ... Maybe someone can try it out and send a PR if it works. |
Beta Was this translation helpful? Give feedback.
-
Here are the guide for use immer with zustand in JSDoc without using /**
* @typedef YourStoreTypes
* @property {Object} foo
* @property {string} foo.bar
* @property {(bar: string) => void} updateBar
*/
export const useStore = (
/** @type {typeof create<YourStoreTypes, [["zustand/immer", never]]>} */(create)(
immer(
(set) => ({
foo: {
bar: 'bar',
},
updateBar: (bar) => {
set(state => {
state.foo.bar = bar
})
},
})
)
)) You can see more detail here |
Beta Was this translation helpful? Give feedback.
-
Summary
The VSCode editor reports that the inferred type is not portable and advises adding a type annotation. Typescript CLI (v4.8.4) doesn't report this as error.
The inferred type is:
The
AppState
type is my custom type. I can importUseBoundStore
andStoreApi
from zustand, butWithImmer
type is not exported from the immer middleware.Could you export the
WithImmer
type as well?Link to reproduction
Check List
Please do not ask questions in issues.
Please fill this template if you're filling an issue regarding TypeScript.
create
is to be used ascreate<T>()(...)
and notcreate<T>(...)
.Beta Was this translation helpful? Give feedback.
All reactions