Skip to content

Instantly share code, notes, and snippets.

@msolli
Last active January 13, 2016 13:18
Show Gist options
  • Save msolli/0c23fd9796a7d2b09916 to your computer and use it in GitHub Desktop.
Save msolli/0c23fd9796a7d2b09916 to your computer and use it in GitHub Desktop.
Flow JSX attributes weirdness
[ignore]
[include]
[libs]
[options]
/* @flow */
import React from "react";
type Foo = { bar: string };
class FooItem extends React.Component {
props: Foo;
render(): ReactElement {
return (
<span>{this.props.bar}</span>
);
}
}
class FooWrapper extends React.Component {
render(): ReactElement {
return (
<div>
<FooItem bar={42} />
</div>
);
}
}
/* @flow */
import React from "react";
type Foo = { bar: string };
export default class FooItem extends React.Component {
props: Foo;
render(): ReactElement {
return (
<span>{this.props.bar}</span>
);
}
}
/* @flow */
import React from "react";
import FooItem from "./fooItem";
class FooWrapper extends React.Component {
render(): ReactElement {
return (
<div>
<FooItem bar={42} />
</div>
);
}
}
@msolli
Copy link
Author

msolli commented Jan 13, 2016

When running Flow on these files, I expect to get the same type error in foo.js as in fooWrapper.js, namely:

 10:                 <FooItem bar={42} />
                     ^^^^^^^^^^^^^^^^^^^^ React element `FooItem`
 10:                 <FooItem bar={42} />
                                   ^^ number. This type is incompatible with
  5: type Foo = { bar: string };
                       ^^^^^^ string. See: fooItem.js:5

Instead, with Flow 0.20.1, I get the following error:

  8:     props: Foo;
                ^^^ property `bar`. Property not found in
 21:                 <FooItem bar={42} />
                     ^^^^^^^^^^^^^^^^^^^^ type parameter `Props` of React element `FooItem`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment