Replies: 10 comments 14 replies
-
The change looks good to me! |
Beta Was this translation helpful? Give feedback.
-
So even the usage of I tried to demonstrate the problem here Of course, there is a solution - to give the explicit return type to the projection function, and maybe that's the right solution, but it's hard when this change is introduce later into a huge codebase. What I what to highlight here is that |
Beta Was this translation helpful? Give feedback.
-
I hear you and agree that this is kinda a breaking-change. Even the example-app tests in this repo has a few usages of projector func that would break. But by not having type-safety here we're losing other perks like language-service support - rename and other stuff.. now when refactoring you have to do it in old way with find & replace. As you said - most of the time this will result in a runtime error, but not every - so because of these few times you still have to go through all your usages and fix it manually, otherwise your codebase soon will lose integrity. Also |
Beta Was this translation helpful? Give feedback.
-
Hey, any chance to revisit it before v11? It's a pain to use projector without type-safety. |
Beta Was this translation helpful? Give feedback.
-
I've run into the same typings problem and wished the Quoting @alex-okrushko
Yes, fixing this issue is definitely worth it, because NgRx itself is a project written in TS. For my part, this makes me expect that types should be handled properly, even in tests. Regarding the breaking change dilemma. When you don't want to break existing functions, there's a classic solution: provide the fixed version under a new name, deprecate the old name, wait for a given period and then remove the old version. You can even do it the other way round (with a little bit of extra effort): rename the current version to maybe Previously: |
Beta Was this translation helpful? Give feedback.
-
What about introducing a new test method instead that is type safe @alex-okrushko? proposed tiny change: david-shortman@e7065b1 By introducing a (hopefully someone could come up with a better named) function like const selectSomeSum = createSelector(a => a, b => b, (a, b) => a + b);
const result = testProjector(selectSomeSum, 1, 2); // 3 this would be enabled by the createSelector updates in #3023 which make inferring the results of the selectors of which a selector is composed easy. |
Beta Was this translation helpful? Give feedback.
-
Just created an issue that was closed as a duplicate of this. Let's not sit on this for another two years. If #3023 (which I really hope will be included in v13) already introduces breaking changes in the
+1 Definitely worth it. I don't even see it being a cost for a huge codebase, even if they've been using |
Beta Was this translation helpful? Give feedback.
-
We can make this a gentle transition. The Then when this change is introduced in some version, it is not breaking, but the loosely typed signature can be marked as deprecated. Then in the subsequent version, the deprecated signature is removed. I'd be happy to open a PR with this approach. |
Beta Was this translation helpful? Give feedback.
-
I've authored a PR that demonstrates a soft introduction for strictness that doesn't affect production code or existing tests. |
Beta Was this translation helpful? Give feedback.
-
@timdeschryver It looks like v14 is approaching with many new PRs. Is there interest in tackling this in v14? My currently open PR uses an opt-in strategy and suggests a path for future migration to carefully take people toward strict projectors. |
Beta Was this translation helpful? Give feedback.
-
Is there a reason why projector function does not have a type-safety for its parameters yet?
This quickly becomes a nightmare when having a lot of unit tests for complicated projectors.
I've looked into internals and found that for some reason the
MemoizedSelector
is using a default typeDefaultProjectorFn
for its projector which does not know anything about parameter types but onlyResult
:This could be easily fixed by explicitly providing a type of projector function (for every
createSelector
of course):Maybe this was already discussed? Are there any hidden issues that I'm not aware of?
Otherwise it's strange why this was not escalated yet.
If accepted, I would be willing to submit a PR for this feature
[x] Yes
[ ] No
I have all the changes ready to be reviewed - just let me know if the solution here is appropriate.
Beta Was this translation helpful? Give feedback.
All reactions