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

0.53+ react types invalid when type import is inlined #134

Open
rosskevin opened this issue Sep 27, 2017 · 2 comments
Open

0.53+ react types invalid when type import is inlined #134

rosskevin opened this issue Sep 27, 2017 · 2 comments

Comments

@rosskevin
Copy link
Contributor

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.

rosskevin added a commit to mui/material-ui that referenced this issue Sep 27, 2017
* flow-typed update

* wow - HOCs seem to finally be typed correctly

* Cleanup, remaining errors seem to be related to withTheme

* [flow] refactor Placement in Tooltip

* [flow] Toolbar

* [flow] FormControl incorrect spec of Margin

* use react-flow-types HigherOrderComponent

* [flow] tabs

* [flow] SvgIcon

* [flow] labels and switches

* [flow] convert to flow typed more components

* re-enable GridWrapper with a flow fix me

* [withStyles] contextTypes defined twice - static inner and outer

* upgrade babel-plugin-flow-react-proptypes

* remove inline type imports - incompatible with current plugin

brigand/babel-plugin-flow-react-proptypes#134

* revert ListItemIcon dive change

* remove remaining $FlowFixMe Props|State
@brigand
Copy link
Owner

brigand commented Sep 28, 2017

@rosskevin thanks for the report. Would you like it to behave exactly the same as the import type { Node } from 'react' result?

@rosskevin
Copy link
Contributor Author

Yes, they are identical in intent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants