gajus / gajus/flow-runtime

Lots of runtime type errors when using React's event types

Open
#196 2 comments 0 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:

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

Which concerns:

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

---

I have a couple questions on the correct way to use flow-runtime in a large project.

### What is the current behaviour?
I have a react component with a field change handler like:

```javascript
// app/MyComponent.js
class MyComponent extends Component {
...
handleFieldChange = (event: SyntheticInputEvent) => {
const { name, value } = event.target;
// onChange logic
}

handleOnSubmit = (event: SyntheticEvent) => {
// onSubmit logic
}

render() {
// render logic
}
}
```

I ran `flow-runtime generate app/MyRuntime.js` and have a couple separate issues here.

1. The main issue is that when the onChange or onSubmit runs, I get a TON of errors output that certain parts of the object are missing, for example:

> Uncaught TypeError: event.currentTarget.forceSpellcheck must be a function
>
> Expected: () => void
>
> Actual Value: undefined
>
> Actual Type: void

(see [this gist](https://gist.github.com/joefiorini/f0dbb21a59df6077d6a5c0b03fe6487f) for the full list).

2. The generated types definition file is HUGE... over 11,000 lines of code and adding about 5.5 minutes to the webpack bulid time
---

### What is the expected behaviour?

1. For the first issue, I guess that the types are incorrect (the properties that are erring should be optional but aren't), but no one has ever really noticed because a missing property wouldn't technically be an error in standard flow.

I'm assuming the solution for that is to find/create my own simplified version of the types that only have what I need. Does anyone know if such types exist already?

2. I would have hoped that this wouldn't add _too_ much overhead to our webpack build, maybe I should instruct babel to ignore files generated by flow-runtime-cli?
---

### Which package versions are you using?

0.17

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.