Files
test-repo/tests/flow/new_react/classes.js
T
Christopher Chedeau 3375cfe605 Move tests around (#454)
* new_tests

* move_all_clobbered_tests

* remove all the tests that no longer exist

* re-run flow tests

* Move all the flow tests to tests/flow and prettier to tests/

* Move prettier tests to their own folders

* Add jsfmt files

* run prettier snapshot tests
2017-01-24 14:35:37 -08:00

84 lines
1.3 KiB
JavaScript

var React = require('React');
type DefaultProps = { };
type Props = { x: number };
type State = { y: number };
class Foo extends React.Component {
props: Props;
state: State;
static defaultProps: DefaultProps;
is_mounted: boolean;
static bar(): void {}
qux(): void {
var _: string = this.props.x;
}
constructor(props) {
super(props);
this.state = { y: "" };
}
setState(o: { y_: string }): void { }
componentDidMount(): void {
this.is_mounted = true;
}
componentWillReceiveProps(
nextProps: Object,
nextContext: any
): void {
this.qux();
}
}
Foo.defaultProps = 0;
var foo: $jsx<number> = <Foo/>;
Foo.bar();
var FooLegacy = React.createClass({
is_mounted: (undefined: ?boolean),
propTypes: {
x: React.PropTypes.number.isRequired
},
getDefaultProps(): DefaultProps { return {} },
statics: {
bar(): void {}
},
qux(): void {
var _: string = this.props.x;
},
getInitialState(): { y: string } {
return { y: "" };
},
setState(o: { y_: string }): void { },
componentDidMount(): void {
this.is_mounted = true;
},
componentWillReceiveProps(
nextProps: Object,
nextContext: any
): void {
this.qux();
},
});
FooLegacy.defaultProps = 0; // TODO: should be error
var foo_legacy: $jsx<number> = <FooLegacy/>;
FooLegacy.bar();