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

Cannot spread same exact immutable types: null or undefined [1] is incompatible with string [2]. #7210

Closed
villesau opened this issue Nov 27, 2018 · 2 comments

Comments

@villesau
Copy link
Contributor

villesau commented Nov 27, 2018

Try Flow

// @flow

type Foo = {| +foo: ?string |};
const test = (bar: Foo): Foo => ({ foo: 'foo', ...bar});

causes:

3: type Foo = {| +foo: ?string |};
                       ^ null or undefined [1] is incompatible with string [2].
References:
3: type Foo = {| +foo: ?string |};
                       ^ [1]
4: const test = (bar: Foo): Foo => ({ foo: 'foo', ...bar});
                                           ^ [2]

This is very strange and frustrating issue, I think there is no any scenario that would make the error valid.

The error location is also very odd: It's in the type, not in the usage. this makes suppressing the error pretty non-optimal.

If I don't spread, the problem disappears.

This happens with all Flow versions.

Happens also without exactness or read-onlyness
possibly undefined version works Unfortunately this is not what our type really is :/

@Gisleburt
Copy link

I'm suffering the same problem. This appears to have been a long standing bug in flow. See #5243

@nmote
Copy link
Contributor

nmote commented Oct 25, 2019

This no longer errors on master

@nmote nmote closed this as completed Oct 25, 2019
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

4 participants