An example of a dynamic thread code shows that a thread can compute type checking at runtime:
function foo(x) {
if (typeof x === 'string') {
return x.length;
} else {
return x;
}
}
var res = foo('Hello') + foo(42);
But in real life, typeofnot good enough. I usually use verification functions like lodash ( _.isFunction, _.isStringetc.), _.isStringhandle a lot of extreme cases.
The problem is that if we change the example to use lodash for type checking at runtime, Flow no longer understands this:
function foo(x) {
if (_.isString(x)) {
return x.length;
} else {
return x;
}
}
var res = foo('Hello') + foo(42);
I tried to use iflow-lodash, but it seems nothing has changed here .
, Flow , lodash ? Flow, .