Flowtype - Can Flowtype Automatically Annotate The Variables' Type?
I have searched the doc of flowtype but I can not find something relevant to type inference, for example: function add(x){ return x+10; } after using flowtype, it becomes: funct
Solution 1:
There is cli commandflow suggest <yourfile>
. Unfortunately it is not as powerful as jsnice and will not help you with this case, but if you apply it for example to
function sub(x, y){
returnx - y;
}
it will suggest you
function sub(x, y): number{
returnx - y;
}
so it is more or less useful.
You can also try to use first the jsnice and then flow-jsdoc which converts jsdoc annotations to flow.
Solution 2:
flow suggest
is indeed the way to go. In general it cannot infer input types for functions that are exported (only un-exported functions used locally in your file), but it can fill in output types of all functions, the types of local variables, etc.
Also note that Flow doesn't infer polymorphic types.
Post a Comment for "Flowtype - Can Flowtype Automatically Annotate The Variables' Type?"