-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Before, type-at-pos on `Foo` in ``` const Foo = React.createClass({ propTypes: { foo: React.PropTypes.string, bar: React.PropTypes.string.isRequired }, getInitialState() { return { baz: 0 }; }, getDefaultProps() { return { foo: "foo" }; } }); ``` returned ``` Class<React$Component> ``` With this change it returns: ``` Class<React$Component<{ bar: string, foo?: string }, {baz: number}>> & { +propTypes: {| bar: React$PropType$Primitive$Required<string>, foo: React$PropType$Primitive<string> |}, defaultProps: { foo: string } } ``` Implementation-wise, the normalizer: 1. Looks up `"props"` on the newly create instance to fill in the `Props` type argument to `React$Component`. Will replace with `any` if it's not found. 2. Looks up `"state"` on the newly create instance to fill in the `State` type argument to `React$Component`. Converts to an inexact version of that type. Will replace with `any` if it's not found. 3. Looks up and includes all static fields of the instance. Reviewed By: samwgoldman Differential Revision: D14486735 fbshipit-source-id: 0ea4259d81b67c1015350878bb41e8badb583fb6
- Loading branch information
1 parent
1159911
commit 94ff166
Showing
4 changed files
with
149 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// @flow | ||
|
||
const React = require("react"); | ||
const Foo = React.createClass({ | ||
propTypes: { | ||
foo: React.PropTypes.string, | ||
bar: React.PropTypes.string.isRequired | ||
}, | ||
getInitialState() { | ||
return { baz: 0 }; | ||
}, | ||
getDefaultProps() { | ||
return { | ||
foo: "foo" | ||
}; | ||
} | ||
}); | ||
|
||
const NoState = React.createClass({ | ||
propTypes: { | ||
foo: React.PropTypes.string, | ||
bar: React.PropTypes.string.isRequired | ||
}, | ||
getDefaultProps() { | ||
return { | ||
foo: "foo" | ||
}; | ||
} | ||
}); | ||
|
||
const NoDefaultProps = React.createClass({ | ||
propTypes: { | ||
foo: React.PropTypes.string, | ||
bar: React.PropTypes.string.isRequired | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters