-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Flow unable to understand trivial variable equivalence when determining refinements #7228
Comments
Refinements are not saved with new variables. It's expected behaviour. Just use already refined variable. |
That becomes complicated in larger scenarios, like: const Text = ({ html, heading }: { html: string, heading: string }) => (
<div>
{heading}
{html}
</div>
);
function Wrapper({ html, heading }: { html?: string, heading?: string }) {
const hasContent = html && heading;
return hasContent && <Text html={html} heading={heading} />;
} |
Unfortunately, our refinement tracking is very conservative and cannot support your use case today. There is no one currently working on making our refinement tracking more complete. |
Thanks for your quick reply, @jbrown215! I'd be interested in helping with testing when somebody picks up this task. |
@rkrv I got very definite answer to same problem here: #6146 (comment) This has been reported many times already. I think that it's because the restriction is not well documented and the use case is pretty idiomatic JS. If you know the restriction, it's very easy to avoid it and still being able write clean code. Just avoid destructing objects that has this kind of "cross dependencies" |
I ran into a issue where flow will not recognise a type of a copied variable for conditional rendering in React:
https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoVBLAtgBzgJwBcwAlAUwEMBjYqfOLMAcn0pqYG50q4A7AZ2IAVMgA9iAXjAAKAN5gAFoSwwwAXwBcYeUpVbB+DLwDm6gJRgJAPkXKYXVFACuvGhj5gA6vgo4cZfDlbFXUtHTsAfn1CQxNzbVQwMB4BYgUKfgAJO0tg+0SwVkInfF5FDOyQgDIqsAAeEXE8iVldGDUwYCsuNVQgA
Funny enough, this will work:
https://flow.org/try/#0PQKgBAAgZgNg9gdzCYAoVBLAtgBzgJwBcwAlAUwEMBjYqfOLMAcn0pqYG50q4A7AZ2IAVMgA9iAXjAAKAN5gAFoSwwwAXwBcYeUpVbB+DLwDm6gJRgJAPkXKYXVFACuvGhj5gA6vgo4cZfDlbFXUtHTsAfn1CQxNzbVQwMGBgMB4BYgUKfgAJO0tg+0SwVkInfF5CsAAyarAAHhFxQolZXRg1ZKsuNVQgA
Am I missing something?
The text was updated successfully, but these errors were encountered: