[flow] add some typings to utils#7104
Conversation
|
@vjeux you are also working on typing so I decided to ask: which of rest utils files I can take? |
src/shared/utils/ReactNodeTypes.js
Outdated
| EMPTY: 2, | ||
|
|
||
| getType: function(node) { | ||
| getType: function(node: ReactElement): number { |
There was a problem hiding this comment.
Instead of returning number, could you do
type ReactNodeType = 0 | 1 | 2;getType: function(node: ReactElement<any>): ReactNodeType {this way it'll prevent people from passing arbitrary numbers, flow will force to use the literal 0, 1, 2 or anything that returns those values. It's not perfect but much better.
|
Thanks! I'm not working on anything else right now so feel free to take whichever you like :) |
src/shared/utils/flattenChildren.js
Outdated
| * @return {!object} flattened children keyed by name. | ||
| */ | ||
| function flattenChildren(children, selfDebugID) { | ||
| function flattenChildren(children: ReactElement<any>, selfDebugID: number): any { |
There was a problem hiding this comment.
Can you type the return function, if we put any, it doesn't bring any benefit since flow is just going to ignore it.
?{ [name: string]: ReactElement<any> }| traverseContext: mixed, | ||
| child: ReactElement<any>, | ||
| name: string, | ||
| selfDebugID: number |
There was a problem hiding this comment.
Sorry, just saw this. selfDebugID is actually an optional parameter that will only be available in dev mode. You can also see from the number= JSDoc annotation. cc @vjeux
* add some typings to utils * add typing of flattenChildren * more accurate typings for flattenChildren (cherry picked from commit 3b5c756)
No description provided.