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 function generic into generic types for args and return value #61

Merged

Conversation

wbinnssmith
Copy link
Contributor

This allows us to specifically reference these types within memoizeOne and is more consistent with how decorators like these are typed elsewhere [1] [2]

This also has the nice side effect of removing the any casting on the memoized function.

This is a breaking change in the case users of memoizeOne were specifying ResultType specifically rather than letting Flow infer the type of it.

It also renames the input function to inputFn instead of resultFn, which I found confusing (I assume this stemmed from the name of the type that served to type both the input and output function). Hope that's all right.

I'm very open to feedback!

Test Plan: yarn test

[1] https://github.com/flow-typed/flow-typed/blob/master/definitions/npm/lodash_v4.x.x/flow_v0.63.x-/lodash_v4.x.x.js#L789
[2] https://github.com/sindresorhus/mem/blob/master/index.d.ts#L74

@wbinnssmith
Copy link
Contributor Author

Note: this also contains #60. Feel free to merge one or both (or none 😆 )

@alexreardon
Copy link
Owner

Loving the improved typing for this one

@wbinnssmith wbinnssmith force-pushed the wbinnssmith/remove-any-types branch 4 times, most recently from 3b1a9da to 59bb7bc Compare April 4, 2019 05:31
@wbinnssmith wbinnssmith force-pushed the wbinnssmith/remove-any-types branch from 59bb7bc to 054faed Compare April 4, 2019 07:01
@alexreardon
Copy link
Owner

This looks good to me! @TrySound can you see any issues?

@alexreardon
Copy link
Owner

I plan on merging this on monday

// `mixed` means that the result can be anything but needs to be checked before usage.
// As opposed to `any`, it does not compromise type-safety.
// See https://flow.org/en/docs/types/mixed/ for more.
export default function memoizeOne<TArgs: mixed[], TRet: mixed>(
Copy link
Contributor

Choose a reason for hiding this comment

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

I would use $ReadOnlyArray

Copy link
Owner

Choose a reason for hiding this comment

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

thanks! /cc @wbinnssmith ?

@alexreardon alexreardon merged commit cbde410 into alexreardon:master Apr 8, 2019
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.

3 participants