Comments (4)
TypeScript is unable to infer TState at the time the complier creates the set
and get
types. They default to GetState<{}>
and SetState<{}>
. You can specify your own types for these in the state creator function you pass in. I have tried to find a workaround for some time now and nothing seems to work.
from zustand.
@JeremyRH would the overload that @dm385 suggested in the PR help?
from zustand.
@drcmda I tried that. You lose type inference for JS. Also it's a little strange to create a wrapper function just to have your types inferred properly. I have another solution that we should test out. #35
from zustand.
I have tested the fix that is now that it is available in 1.0.2
. Unfortunately, as far as I can see, the proposed fix fixes very basic usages, but as soon as you plan to do generic things (in other words, as soon as you encapsulate the zustand create
function in another function, the fix doesn't work anymore.
from zustand.
Related Issues (20)
- blacklist and whitelist
- Argument of type '(state: ClientStore) => Client | undefined' is not assignable to parameter of type 'ClientStore | Partial<ClientStore> | ((state: ClientStore) => ClientStore | Partial<ClientStore>)'. Type '(state: ClientStore) => Client | undefined' is not assignable to type '(state: ClientStore) => ClientStore | Partial<ClientStore>'. Type 'Client | undefined' is not assignable to type 'ClientStore | Partial<ClientStore>'. Type 'undefined' is not assignable to type 'ClientStore | Partial<ClientStore>'.ts(2345)
- The value I save to storage with persist is delayed when the page refreshes.
- State updated in one component but not in another one
- Typescript + Slices = trouble HOT 7
- Setting nested state make the other states change (their values didn't change)
- zustand concurrent update issue
- Typo in GitHub "About" HOT 1
- import { create ,WritableDraft} from "zustand" HOT 1
- Introduction Zustand page a documentation typo HOT 1
- Ts error on type annotation HOT 3
- Persist middleware keeping old versions of functions around. Breaking apps when deploying to prod
- devtools with option `serialize.immutable` does not deserialize state from devtools correctly (broken redux devtools "Jump" / "Revert" etc.)
- state empty on first render HOT 1
- onRehydrateStorage is invoked before storeage.getItem HOT 1
- About API
- About api docs
- Documentation incorrect: Usage with React Contexts HOT 2
- "useEffect" is not exported by "node_modules/react/index.js"
- Usage of import.meta.env
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zustand.