-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Union types & Default params #2093
Comments
@samwgoldman Any update on this? Similar issue in Flow v0.41.0: // BlockTitle.js
// ...
type Props = {
children?: React$Element<any>,
className?: string,
headerClassName?: string,
size?: number | string,
theme: Theme,
}
const BlockTitle = ({
children,
className = '',
headerClassName = '',
size = 3,
theme,
}: Props) => {
// ... And the error:
|
I think I'm seeing this same issue. Is there any progress being made on this? or any solid workarounds? Here's my example I'm running into: tryflow example |
Same here, also with state. |
I'm running into this issue as well, to me it looks like an inconsistency in how Flow handles union types and destructuring with default values: type Obj = { foo?: string | number };
// Error: "Cannot assign `{...}.foo` to `foo` because string [1] is incompatible with number [2]."
const { foo = 1 }: Obj = {};
// Works!
const obj: Obj = {};
const { foo: bar = 1 } = obj;
// Works!
const baz: $PropertyType<Obj, 'foo'> = 1; The first example exhibits the problem in question. The second problem is what I feel the first one ought to be equivalent to (unless I'm misunderstanding how the type syntax applies to the left-hand side of the assignment). The third example demonstrates that it isn't a problem with assignments to the union type itself, but only when the assignment happens as a default value when destructuring. This is also seen in #183 (comment). Possibly more issues as well. I'm surprised this hasn't been addressed since it seems like a common case that a lot of people run into, and an interaction of fairly basic JS features. Perhaps it's just not a code style that's used much at facebook? |
/cc @samwgoldman was this fixed? |
Fixed in de994b6 |
Search terms: destructuring, default arguments, default parameters, union
eg:
It's strange that it happens only for default value assignment in object destructuring -
fn
and not an object definition -x
.This does NOT happen in Flow 0.28. But flow 0.29 throws errors.
The text was updated successfully, but these errors were encountered: