-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
RFC: Capture the type of a selector's projector function in the MemoizedSelector type #1908
Comments
Having the projector to be any bothered me as well. Would this be a better solution? export interface MemoizedSelector<State, Result>
extends Selector<State, Result> {
release(): void;
projector: (...args: any[]) => Result;
setResult: (result?: Result) => void;
} I'd rather not add third parameter to the MemoizedSelector (that doesn't have a default value) - it would break the world for me. |
I would propose adding a default value of |
@brandonroberts, @alex-okrushko To follow on, I would say that the interface provides a default value for the new third generic parameter: export interface MemoizedSelector<State, Result, ProjectorFn = AnyFn>
extends Selector<State, Result> {
release(): void;
projector: ProjectorFn;
setResult: (result?: Result) => void;
} but using inference from |
This looks like a non-breaking change (unless some code erroneously was relying on a different return type). export type DefaultProjectorFn<T> = (...args: any[]) => T;
export interface MemoizedSelector<State, Result, ProjectorFn = DefaultProjectorFn<Result>>
extends Selector<State, Result> {
release(): void;
projector: ProjectorFn;
setResult: (result?: Result) => void;
} WDYT? |
👍 |
I will take this one 👍 |
When testing a memoized selector's projector function we default the type of the projector to be
any
. This makes it difficult to catch type changes of the projector function in unit tests.I recommend the type of
MemoizedSelector
be extended to have a third type parameter that captures the type of the projector function:Describe any alternatives/workarounds you're currently using
Live with the lack of type safety. 😄
Other information:
If accepted, I would be willing to submit a PR for this feature
[X] Yes (Assistance is provided if you need help submitting a pull request)
[ ] No
The text was updated successfully, but these errors were encountered: