reduxjs / reselect

Selector library for Redux
MIT License
19.04k stars 670 forks source link

fix types on resultFunc (#591) #592

Closed bdwain closed 1 year ago

bdwain commented 1 year ago

Fixes #591

Happy to make tweaks to this, but I think it's roughly what is needed to fix the broken types

From original issue.

I think there are incorrect types for the resultFunc property that you can pull off of a created selector. I am on version 4.1.7

function isOdd(num: number): boolean {
  return num % 2 === 1;
}

const memoizedIsOdd = createSelector([isOdd], (bool: boolean) => bool);

memoizedIsOdd.resultFunc(true).clearCache(); //doesn't exist, but the types think it does

clearCache is only on the actual selector returned by createSelector, not the return value of result func. The types think it's on both though.

node output:

Welcome to Node.js v16.18.1.
Type ".help" for more information.
> function isOdd(num) {
...   return num % 2 === 1;
... }
undefined
>
> const { createSelector } = require('reselect')
undefined
> createSelector
[Function: createSelector]
> const memoizedIsOdd = createSelector([isOdd], (bool) => bool);
undefined
> memoizedIsOdd.resultFunc.clearCache
undefined
> memoizedIsOdd.clearCache
[Function (anonymous)]
> memoizedIsOdd.resultFunc(true)
true
> memoizedIsOdd.resultFunc(true).clearCache
undefined
> memoizedIsOdd.resultFunc(true).clearCache()
Uncaught TypeError: memoizedIsOdd.resultFunc(...).clearCache is not a function
>
codecov[bot] commented 1 year ago

Codecov Report

Merging #592 (9d5ec54) into master (474b12c) will not change coverage. The diff coverage is n/a.

Additional details and impacted files [![Impacted file tree graph](https://codecov.io/gh/reduxjs/reselect/pull/592/graphs/tree.svg?width=650&height=150&src=pr&token=p4mRPDVRyT&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=reduxjs)](https://codecov.io/gh/reduxjs/reselect/pull/592?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=reduxjs) ```diff @@ Coverage Diff @@ ## master #592 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 2 2 Lines 105 105 Branches 24 24 ========================================= Hits 105 105 ``` | [Impacted Files](https://codecov.io/gh/reduxjs/reselect/pull/592?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=reduxjs) | Coverage Δ | | |---|---|---| | [src/index.ts](https://codecov.io/gh/reduxjs/reselect/pull/592/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=reduxjs#diff-c3JjL2luZGV4LnRz) | `100.00% <ø> (ø)` | |
markerikson commented 1 year ago

Seems reasonable at first glance. Thanks!

I'll try to publish a new version no later than this weekend.

bdwain commented 1 year ago

thanks!

Kamahl19 commented 1 year ago

@markerikson Hey, could you please publish a new version with this fix? Thanks a lot!