-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Pick<> not working in React setState with updater function #16923
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
Comments
I have reduced your problem down to the typing that is causing the problem. let f:Pick< { value: string }, never> = () => { return { a:1 }}
` |
On a related note, it seems the "broken" version here was the best fix for setting via a dynamic index. Consider this snippet, modelled after the "Multiple Inputs" section at https://facebook.github.io/react/docs/forms.html but with TS where state satisfies a particular interface:
Will this break if the issue here is fixed? Is there a cleaner way to write it? |
There's been some discussion (but no resolution) of this over in DefinitelyTyped/DefinitelyTyped#18365 |
This issue has been marked as 'External' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx)
The React
setState(...)
function fails to detect incompatible value being returned from an updater function.Pick<>
does not seem to work well in this case. I thought this would be fixed in v2.4 but it is not.The issue migh be related to this one #13359 but it does not seem to be limited to conditional updates.
Code
Expected behavior:
Compiler detects wrong return type of the updater function passed to
this.setState(...)
. (Overload which accepts object (not the updater function) reports an error correctly.)Actual behavior:
Compiler fails to detect wrong return type of the updater function passed to
this.setState(...)
. No error reported even though argument{ valueWithTypo: value }
is not compatible with state type{ value: string }
.The text was updated successfully, but these errors were encountered: