You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using createSelector from Reselect, I've encountered a rare edge case affecting TypeScript type inference. This issue arises specifically when passing input selectors as separate inline arguments composed of inline function declarations.
Detailed Behavior
✔️ Working Scenario 1: Input selectors as inline function declarations in a single array works fine.
✔️ Working Scenario 2: Input selectors as function declarations passed as separate arguments, defined outside of createSelector works fine.
❌ Problematic Scenario: Inline function declarations as separate arguments in createSelector cause TypeScript to resolve the parameter types of the result function to unknown.
❌ Problematic Scenario - Result Function Loses its Types:
constselectTodoIds=createSelector(functionselectTodos(state: RootState){returnstate.todos;},functionselectId(state: RootState,id: number){returnid;},(todos,id)=>todos.map(todo=>todo.id)// ❌ Here, both `todos` and `id` resolve to a type of `unknown`.);
Impact
Although this situation may not happen very often and this issue may not be common, it's important to document for those who might encounter it.
Workarounds
Several simple workarounds include:
Using arrow functions instead of inline function declarations.
Grouping input selectors into a single array.
Defining the function declarations outside of createSelector.
Either one of these methods solves the problem.
Conclusion
This might be one of those issues that might eventually just go away as TypeScript gets better, but documenting it with potential workarounds can assist others potentially facing similar challenges.
The text was updated successfully, but these errors were encountered:
Overview
When using
createSelector
from Reselect, I've encountered a rare edge case affecting TypeScript type inference. This issue arises specifically when passing input selectors as separate inline arguments composed of inline function declarations.Detailed Behavior
createSelector
works fine.createSelector
cause TypeScript to resolve the parameter types of the result function tounknown
.Reproduction
Here are the different scenarios for clarity:
✔️ Scenario 1 - Works Fine:
✔️ Scenario 2 - Works Fine:
❌ Problematic Scenario - Result Function Loses its Types:
Impact
Although this situation may not happen very often and this issue may not be common, it's important to document for those who might encounter it.
Workarounds
Several simple workarounds include:
createSelector
.Either one of these methods solves the problem.
Conclusion
This might be one of those issues that might eventually just go away as TypeScript gets better, but documenting it with potential workarounds can assist others potentially facing similar challenges.
The text was updated successfully, but these errors were encountered: