-
Notifications
You must be signed in to change notification settings - Fork 670
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
Changes from all commits
71edb87
95a02c3
a2d0722
9a3b415
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,8 @@ import { | |
createSelectorCreator, | ||
createStructuredSelector, | ||
ParametricSelector, | ||
OutputSelector | ||
OutputSelector, | ||
SelectorResultArray | ||
} from '../src/index' | ||
|
||
import microMemoize from 'micro-memoize' | ||
|
@@ -162,8 +163,8 @@ function testInvalidTypeInCombinator() { | |
|
||
// does not allow heterogeneous parameter type | ||
// selectors when the combinator function is typed differently | ||
// @ts-expect-error | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
createSelector( | ||
// @ts-expect-error | ||
(state: { testString: string }) => state.testString, | ||
(state: { testNumber: number }) => state.testNumber, | ||
(state: { testBoolean: boolean }) => state.testBoolean, | ||
|
@@ -990,3 +991,32 @@ function createSelectorConfigOptions() { | |
} | ||
) | ||
} | ||
|
||
// Issue #526 | ||
function testInputSelectorWithUndefinedReturn() { | ||
type Input = { field: number | undefined } | ||
type Output = string | ||
type SelectorType = (input: Input) => Output | ||
|
||
const input = ({ field }: Input) => field | ||
const result = (out: number | undefined): Output => 'test' | ||
|
||
// Make sure the selector type is honored | ||
const selector: SelectorType = createSelector( | ||
({ field }: Input) => field, | ||
args => 'test' | ||
) | ||
|
||
// even when memoizeOptions are passed | ||
const selector2: SelectorType = createSelector( | ||
({ field }: Input) => field, | ||
args => 'test', | ||
{ memoizeOptions: { maxSize: 42 } } | ||
) | ||
|
||
// Make sure inference of functions works... | ||
const selector3: SelectorType = createSelector(input, result) | ||
const selector4: SelectorType = createSelector(input, result, { | ||
memoizeOptions: { maxSize: 42 } | ||
}) | ||
Comment on lines
+1017
to
+1021
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} |
There was a problem hiding this comment.
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.