-
Notifications
You must be signed in to change notification settings - Fork 674
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] defaultMemoize errors #384
Comments
I'm also facing this error, is there any news on that? |
any news? facing same error! really annoying |
Hey all! Wondering if this has had any updated at all? I'm looking foward to remove the ts-ignore I put 😄 |
I have the same issue. |
Any update on this? It's been 1.5 years |
More than 2 years now. I suppose this PR fixes it? #465 |
I don't think anything in #480 would fix this, but it does look like #465 might. Honestly, it's worth noting this edge case and making sure we have it in the type updates planned for v5. Later I can verify if #465 would fix this. Either way, #465 is looking to get pulled into 4.x soon. If #465 doesn't fix it, we can probably find another non-breaking way to fix this for 4.x too. |
I'm poking around at this atm as part of #485 . After dropping in the complete overhaul of the types for TS 4.2, tweaking the |
Hmm. It seems like part of the issue here is that the TS types say that the <T>(a: T, b: T, index: number) => boolean But, if you look at the actual runtime behavior, there isn't any for (let i = 0; i < length; i++) {
if (!equalityCheck(prev[i], next[i])) {
return false
}
} Interestingly, we also have a pair of type tests that create dummy equality functions that expect an Digging back through the actual source history, it looks like that may have been accurate up until late 2016. Originally, the comparison was run by passing it to const isEqualToLastArg = (value, index) => equalityCheck(value, lastArgs[index])
return (...args) => {
if (
lastArgs === null ||
lastArgs.length !== args.length ||
!args.every(isEqualToLastArg)
) {
lastResult = func(...args)
}
lastArgs = args
return lastResult
}
} which would have indeed passed through an So, the typedefs have been broken there for five years :) If I extract a separate export type EqualityFn<T> = (a: T, b: T /*, index: number*/) => boolean
export function defaultMemoize<F extends (...args: any[]) => any, T>(
func: F, equalityCheck?: EqualityFn<T>,
): F;
export function createSelectorCreator(
memoize: <F extends (...args: any[]) => any>(func: F) => F,
): typeof createSelector;
export function createSelectorCreator<T>(
memoize: typeof defaultMemoize,
equalityCheck: EqualityFn<T>
) : typeof createSelector I'm not sure if this is necessarily the "right" or "best" answer, but it seems to solve the issue. |
- Extracted standalone `EqualityFn` type - Removed incorrect `index` param from equality args - Added specialized overload of `createSelectorCreator` specifically for usage with `defaultMemoize`, for better inference Ref: reduxjs#384 (comment)
I just published https://github.com/reduxjs/reselect/releases/tag/v4.1.0-alpha.0 , which should fix this issue. Can folks try it out and give us feedback? |
It fixed my issue :) |
@spassvogel Nice. I actually made further progress last night - in my local build, I hope to put another alpha this evening - would appreciate it if you could try that out as well. |
Should be fixed by #486 . |
Current TS definitions show error for the following usages:
Results in:
This also happens when creating memoized function:
Possible solution:
When I change:
to:
Everything works as expected but I'm not sure if that's correct approach.
The text was updated successfully, but these errors were encountered: