Comments (9)
I'm kinda confused. Can you give an example of when you feel you need to explicitly specify the type?
Reselect's current types are designed to infer as much as possible, and you generally shouldn't be explicitly providing generic arguments to createSelector
.
from reselect.
At the moment, we have recently migrated a large project from flow to typescript and the typing of the code leaves much to be desired. Automatic type inference often outputs any. By explicitly specifying the types for the combiner, we also fix the composition of selectors inside createSelector
from reselect.
You're supposed to use Reselect the other way around :)
Type the input function arguments correctly, and everything else should get inferred right.
In this case, go back to the definitions of selectCheckoutCartGroups
, selectCheckoutCarts
, etc, and make sure that their input functions have the right types, like:
const selectCheckoutCartGroups = createSelector(
(state: RootState) => state.some.cart,
(state: RootState, someOtherArg: number) => someOtherArg,
(cart, someOtherArg) => // whatever here
)
// selectCheckoutCartGroups is now typed as;
// (state: RootState, someOtherArg: number) => whateverYourReturnValueIs
Do that for each of those selectors, and the types will propagate through correctly.
from reselect.
While we're at it, what is this stateCreator
function?
from reselect.
While we're at it, what is this
stateCreator
function?
Probably a bad example
This is a legacy code, there is nothing good there, unfortunately :)
from reselect.
You're supposed to use Reselect the other way around :)
Type the input function arguments correctly, and everything else should get inferred right.
In this case, go back to the definitions of
selectCheckoutCartGroups
,selectCheckoutCarts
, etc, and make sure that their input functions have the right types, like:const selectCheckoutCartGroups = createSelector( (state: RootState) => state.some.cart, (state: RootState, someOtherArg: number) => someOtherArg, (cart, someOtherArg) => // whatever here ) // selectCheckoutCartGroups is now typed as; // (state: RootState, someOtherArg: number) => whateverYourReturnValueIsDo that for each of those selectors, and the types will propagate through correctly.
Yes, this is the ideal option that we are striving for. Unfortunately, now at the moment there is a need for part of the team to type explicitly. Even the described types do not always give the expected result. To increase readability, we would like to remove an extra parameter that is duplicated in the type. Of the options was to redefine them locally or come here with a suggestion :)
from reselect.
@AlbertFib : why do you need to "type explicitly"?
from reselect.
@AlbertFib : why do you need to "type explicitly"?
In some places we consciously want to type explicitly and control the return type of the created selector, and not rely on automatic output, so that if the selector changes, we get a type error in this place.
from reselect.
Honestly, you're bringing the pain upon yourself :)
We designed Reselect's types to infer as much as possible, so that you don't have to write all the types out explicitly.
Given that, I don't think we're going to make a change here.
from reselect.
Related Issues (20)
- Conflicting examples in the docs HOT 3
- 5.0.0-beta.0 breaks ESM in redux-toolkit to 2.0.0-beta.3?.. HOT 5
- Investigate potential memory leak issues with `weakmapMemoize` HOT 14
- unstable_autotrackMemoize Errors HOT 1
- How to type redux state and selectors with readonly? HOT 3
- Consider dev mode checks for `x => x` result functions HOT 2
- More Reselect addons to investigate HOT 1
- Add identifiable information to dev mode check log messages HOT 3
- Documentation ignores links in the table of contents entries HOT 1
- Type loss in `createSelector` with inline function declarations passed as separate arguments
- lastResult.deref is not a function (it is undefined) HOT 6
- Better call stack for selector warnings HOT 11
- Unable to use `resultEqualityCheck` with `weakMapMemoize` HOT 3
- Incorrect weakMapMemoize alternative example using useCallback HOT 1
- using createSelector.withTypes prevents build HOT 7
- Question: Why can't we support `createAsyncSelector`? HOT 7
- TypeError: (0 , _reselect.createSelector) is not a function HOT 12
- `weakMapMemoize` with `resultEqualityCheck` is provided empty objects for first call. HOT 3
- Library do not work in Safari < 14.1 HOT 1
- Why the LRUCache implementation is using Array over the Doubly Linked List with Map? HOT 8
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 reselect.