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

[TS] incorrect type inference when using curried function with initial state #273

Closed
aleclarson opened this issue Dec 16, 2018 · 4 comments

Comments

@aleclarson
Copy link
Member

let fn = produce((draft: number|string) => {}, Math.random())
fn('undefined')

In the example above, the recipe function signature should take precedence over the initial state's type.

@aleclarson aleclarson added the bug label Dec 16, 2018
@aleclarson aleclarson self-assigned this Dec 16, 2018
aleclarson added a commit that referenced this issue Dec 17, 2018
The base type should be inferred from the recipe function whenever possible.

Fixes #273
@aleclarson
Copy link
Member Author

Addressed by 80b91f8

@mweststrate
Copy link
Collaborator

mweststrate commented Dec 18, 2018

I had quite some issues in the past if TS needs to infer the type from something you pass to it (it usually works for direct functions if not too complex, but not beyond that). I think in general you'll be more safe by writing
let fn = produce<number|string>(draft => {}, Math.random())

@aleclarson
Copy link
Member Author

@mweststrate I've figured it out already. Just not pushed yet.

aleclarson added a commit that referenced this issue Dec 18, 2018
- infer the base type properly
- infer the return type properly
- ensure `nothing` can be distinguished from `undefined`
- allow rest arguments for curried producer w/o initial state

Fixes #273
Fixes #274
Fixes #275
@aleclarson
Copy link
Member Author

🎉 This issue has been resolved in version 1.9.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

No branches or pull requests

2 participants