We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I'm not sure but I think that this might be a Flow bug. I'm unable to add Flow typing when using Object.assign to provide default values for function arguments. Here is a SO question: https://stackoverflow.com/questions/51422411/flow-default-values-type-checking/51431098
Object.assign
And here is a direct link to reproduce this problem on flow.org/try: https://flow.org/try...
Any help will be appreciated.
The text was updated successfully, but these errors were encountered:
Your problem can be reduced to a simpler example—with intersection types, optional and non-optional properties don’t mix well:
// @flow type ConfigIn = {someValue?: number}; type Config = ConfigIn & {someValue: number}; const c: Config = {someValue: 1000}; // error!
(Potentially related: #5929.)
Using the type-spread operator (...) instead fixes this, and fixes the downstream problem in your example:
...
// @flow type ConfigIn = {someValue?: number}; type Config = {...ConfigIn, someValue: number}; function test(config: ConfigIn): number { const myConfig: Config = Object.assign( {}, {someValue: 1000}, config ); return otherFunction(myConfig.someValue); } function otherFunction(input: number): number { return 123; }
Frankly, intersection types seem to break more often than they work. I avoid them altogether.
Sorry, something went wrong.
Thanks, this is it.
What is more, for anyone interested, it is sometimes good to use Exact object types to avoid nested properties problem example and solution
No branches or pull requests
I'm not sure but I think that this might be a Flow bug. I'm unable to add Flow typing when using
Object.assign
to provide default values for function arguments. Here is a SO question: https://stackoverflow.com/questions/51422411/flow-default-values-type-checking/51431098And here is a direct link to reproduce this problem on flow.org/try: https://flow.org/try...
Any help will be appreciated.
The text was updated successfully, but these errors were encountered: