Skip to content
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

Split out optional last argument (memoizeOptions) into it's own overload #530

Merged
merged 4 commits into from
Oct 26, 2021

Conversation

eXamadeus
Copy link
Contributor

Fixes #526

The union type in for the items array in the CreateSelectorFunction type was having difficulty discerning its type. I wrote up some examples of where TS struggles here and made a playground. Link to playground.

…oad since TS can't figure out spread unions easily
@codecov
Copy link

codecov bot commented Oct 26, 2021

Codecov Report

Merging #530 (9a3b415) into master (352afce) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #530   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            2         2           
  Lines          102       102           
  Branches        24        24           
=========================================
  Hits           102       102           
Impacted Files Coverage Δ
src/index.ts 100.00% <ø> (ø)

@@ -98,7 +98,7 @@ export function createSelectorCreator<
// we wrap it in an array so we can apply it.
const finalMemoizeOptions = Array.isArray(memoizeOptions)
? memoizeOptions
: ([ memoizeOptions ] as MemoizeOptions)
: ([memoizeOptions] as MemoizeOptions)
Copy link
Contributor Author

@eXamadeus eXamadeus Oct 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prettier forced these changes...not sure why they were missing from the main branch...due to not wanting to battle my very opinionated IDE (and turn prettier off), I left them in.

@@ -162,8 +163,8 @@ function testInvalidTypeInCombinator() {

// does not allow heterogeneous parameter type
// selectors when the combinator function is typed differently
// @ts-expect-error
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error is exactly the same here, just at a higher level. It still provides the same insight.

Comment on lines +1016 to +1020
// Make sure inference of functions works...
const selector3: SelectorType = createSelector(input, result)
const selector4: SelectorType = createSelector(input, result, {
memoizeOptions: { maxSize: 42 }
})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I caught this while trying to make the examples! And the fix also solves this use case.

@blovato
Copy link

blovato commented Oct 26, 2021

I'm running into similar type issues with 4.1.0.
Seeing this error (among many others):

../../node_modules/@reduxjs/toolkit/dist/index.d.ts(5,25): error TS2305: Module '"reselect"' has no exported member 'OutputParametricSelector'.

Was reselect previously exporting OutputParametricSelector, but no longer is?

@eXamadeus
Copy link
Contributor Author

I'm running into similar type issues with 4.1.0.

Seeing this error (among many others):


../../node_modules/@reduxjs/toolkit/dist/index.d.ts(5,25): error TS2305: Module '"reselect"' has no exported member 'OutputParametricSelector'.

Was reselect previously exporting OutputParametricSelector, but no longer is?

I'm out to dinner, so can't check easily but I'm pretty sure that was removed. According to my memory, we were able to combine the type signature for the parametric selectors with the regular selectors.

@markerikson
Copy link
Contributor

It was removed but I'd re-added it for compat purposes.

Ironically RTK doesn't even use OutputParametricSelector - it just re-exports it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New typing does not work correctly with input selector with undefined return type
3 participants