Comments (3)
@soeik my apologies for not seeing this sooner. No I don't think you're doing anything wrong. This is just the way TypeScript handles excess property checking. Here's a decent article on the subject. If you want to get a type error, you'd need to specifically annotate the return type of the update function in swap
, like this:
export const setIsLoading = (isLoading: boolean) =>
swap<AppState>(appState, (state): AppState => ({
...state,
foo: 0, // now there's an error
isLoading,
}))
I'm sure there's a way I could improve the typings for swap
to make it prevent excess properties more strictly. Don't have the time to mess with it right now, but if anyone wants to PR that feature, I wouldn't be opposed.
However, the excess property should be innocuous. The Atom
's type will remain unchanged, so you won't be able to read any excess properties that get put in there. I guess theoretically, this does pose as a sort of memory leak if your app happens to continually add dynamically generated properties to the Atom
, because they'd never be able to be garbage collected.
from react-atom.
Going to close this for now, feel free to comment further.
from react-atom.
Thank you so much for the explanation. Now I see what's happening. And I don't see any way to fix this, to be honest, unless TS introduces something like the exact type.
from react-atom.
Related Issues (20)
- Your .dependabot/config.yml contained invalid details HOT 1
- optimize `select` option in `useState` HOT 1
- Introducing the useAtomState hook
- optimize `swap` to run selectors prior to useState hooks HOT 2
- storing `initialAtomValById` is unnecessary HOT 1
- useAtom Destructuring HOT 6
- Double renders HOT 1
- options.select fails to return correct value when atom is swapped HOT 1
- make `swap` automatically merge return value of `updateFn` with `state` HOT 4
- Bootstrapping an Atom from localStorage... how to?
- `useAtom` `options.select` gets mixed up when more than one atom HOT 1
- Documentation Suggestion for a difference between "set" and "swap" HOT 2
- add to usehooks page HOT 2
- Subscription list is invalidated if a parent unmounts a child. HOT 10
- Debugging State HOT 1
- HOC for use with non hook components HOT 1
- How to use `Atom` in component state with context ? HOT 1
- Outdated react-dom peer dependency HOT 3
- `set` type signature should enforce next state be same type as current state HOT 1
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 react-atom.