gajus / gajus/flow-runtime

Type spread on imported types doesn't work

Open
#230 3 comments 3 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
797
Forks
49
PR merge metrics
No merged PRs in 30d

Description

This is a:

- [x] Bug Report
- [ ] Feature Request
- [ ] Question
- [ ] Other

Which concerns:

- [ ] flow-runtime
- [x] babel-plugin-flow-runtime
- [ ] flow-runtime-validators
- [ ] flow-runtime-mobx
- [ ] flow-config-parser
- [ ] The documentation website

---

### What is the current behaviour?

Example:
```
import type { Bar } from './types';

type Foo = {|
...Bar,
foobar: string,
|};
```
If a `type` is imported from external file and spread into another `type` the following error is thrown: `TypeError: Invalid attempt to spread non-iterable instance`.

It seems like that at this point the `@babel/flow` preset already stripped out the types so it tries to spread `undefined`.

But if both types are declared in the same file everything works fine.

To showcase this bug I created a minimal reproducible example over here: https://github.com/risetechnologies/flow-runtime-bug

---

### What is the expected behaviour?

It should be possible to spread a type from external file into another type.

---

### Which package versions are you using?

```
flow-runtime: 0.17.0
babel-plugin-flow-runtime: 0.19.0
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the minimal reproducible example at https://github.com/risetechnologies/flow-runtime-bug and inspect babel-plugin-flow-runtime's handling of object type spreads across imported files. Compare the generated behavior for imported and same-file types, then verify that the external spread works without the non-iterable error and add coverage for the reported example.

Written by the indexing model from the issue text.

Assessment

Tech stack
babel, javascript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.