-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeScript: usage of DeepPartial
for preloadedState
is too deep
#2808
Comments
I'm not sure it's possible without some kind of black magic. The crucial part here is Given some type |
There’s a comment in #2679 that it needs to be a deep partial, and not just partial. But hunting through the issues and PRs I’m not seeing why? Partial would have fixed the issue without adding new issues... even in the case of nested combined reducers. What am I missing? What’s the scenario that required deep partial? |
With only using DeepPartial is the closest we could come up with at the time - but has the issue that if a reducer returns an object rather than a single/array value it extends the optional setting one level too far.. :( |
Ah, I had read that before, but it didn't compute until I did a little more experimenting. I can think of two solutions.
What do you think? I'm leaning toward option 2, because |
I've opened a pull request for this issue. #3485 |
…artial). (#3485) * Preloaded state is now selectively partial (instead of deeply partial). * Improved CombinedState, PreloadedState, and removed UnCombinedState. Found a better way to type check CombinedState which allows the $CombinedState symbol property marker to be optional. Since it's optional, it's no longer necessary to strip it off in the Reducer state parameter type and return type. This leaves the type definition for Reducer unmodified, reduces the number of types required by one, and makes the resolved types and stack traces clearer. * Small change to the description of CombinedState. * Removed DeepPartial import from tests. Leaving the definition in place as removing it would be a breaking change. * Made prettier happy. * Made prettier happy with UsingObjectSpreadOperator.md
…eeply partial). (reduxjs#3485) * Preloaded state is now selectively partial (instead of deeply partial). * Improved CombinedState, PreloadedState, and removed UnCombinedState. Found a better way to type check CombinedState which allows the $CombinedState symbol property marker to be optional. Since it's optional, it's no longer necessary to strip it off in the Reducer state parameter type and return type. This leaves the type definition for Reducer unmodified, reduces the number of types required by one, and makes the resolved types and stack traces clearer. * Small change to the description of CombinedState. * Removed DeepPartial import from tests. Leaving the definition in place as removing it would be a breaking change. * Made prettier happy. * Made prettier happy with UsingObjectSpreadOperator.md Former-commit-id: 41c0612 Former-commit-id: b41174f
…eeply partial). (reduxjs#3485) * Preloaded state is now selectively partial (instead of deeply partial). * Improved CombinedState, PreloadedState, and removed UnCombinedState. Found a better way to type check CombinedState which allows the $CombinedState symbol property marker to be optional. Since it's optional, it's no longer necessary to strip it off in the Reducer state parameter type and return type. This leaves the type definition for Reducer unmodified, reduces the number of types required by one, and makes the resolved types and stack traces clearer. * Small change to the description of CombinedState. * Removed DeepPartial import from tests. Leaving the definition in place as removing it would be a breaking change. * Made prettier happy. * Made prettier happy with UsingObjectSpreadOperator.md Former-commit-id: 41c0612 Former-commit-id: b41174f
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Since #2679, we use
DeepPartial
for the type ofpreloadedState
.This means that, given a state tree, all properties at any level in the tree are optional.
What is the expected behavior?
Given a state tree, only properties whose state is computed by a reducer should be optional. This is because reducers have initial state, but the state within them may be required (unless those properties are explicitly marked as optional or they represent reducers).
Which versions of Redux, and which browser and OS are affected by this issue? Did this work in previous versions of Redux?
N/A
/cc @aikoven @dawnmist
I'm not quite sure how we can write the type definition to match the expected behaviour. Any ideas?
Related #2552
The text was updated successfully, but these errors were encountered: