brigand / brigand/babel-plugin-flow-react-proptypes
0.53+ react types invalid when type import is inlined
- Dominant language
- JavaScript
- Stars
- 427
- Forks
- 42
- PR merge metrics
- No merged PRs in 30d
Description
I'm using the new types, and getting invalid errors, only when I inline the `type` import.
e.g.
```
Warning: Failed prop type: Invalid prop `children` of type `Array` supplied to `Toolbar`, expected instance of `Node`.
in Toolbar (created by withStyles(Toolbar))
in withStyles(Toolbar) (at AppFrame.js:177)
```
```
Toolbar.propTypes = process.env.NODE_ENV !== "production" ? {
children: typeof Node === 'function' ? require('prop-types').instanceOf(Node) : require('prop-types').any,
} : {};
```
```
import React, { type Node } from 'react';
type Props = {
children?: Node,
};
```
When I `import type { Node } from 'react'` then I get something more appropriate:
```
var babelPluginFlowReactPropTypes_proptype_Node = require('react').babelPluginFlowReactPropTypes_proptype_Node || require('prop-types').any; // weak
Toolbar.propTypes = process.env.NODE_ENV !== "production" ? {
children: typeof babelPluginFlowReactPropTypes_proptype_Node === 'function' ? babelPluginFlowReactPropTypes_proptype_Node : require('prop-types').shape(babelPluginFlowReactPropTypes_proptype_Node),
} : {};
```
An easy workaround is to not use inlined imports; it took me a while to find this. Not sure how hard this would be to fix but I'm happy to just _not_ use inlined.
Contributor guide
Assessment
This issue has not been assessed yet.