Closed zerkms closed 9 years ago
@zerkms it does some static checks but it's not intended as a replacement for flow, rather a companion to it. We don't do type inference, and we don't check callsites because the current babel API rather limits our ability to do it usefully. If you don't annotate a function with type information, we don't modify the function at all.
It'll currently refuse to compile cases like this, where we know the return value definitely violates the contract:
function foo (): string {
if (true) {
return "foo"; // ok
}
else {
return false; // SyntaxError
}
}
Given your example, if we change it to:
function foo (x: string): string {
return x * 10;
}
We'll get a runtime type error but it's not yet clever enough to do it at compile time. It's trivial to add so I'll leave this issue open until that gets fixed.
I see. For some reason I thought it internally uses flow, but it's just another implementation for the same syntax.
Thanks.
I've taken the first example from http://flowtype.org/docs/five-simple-examples.html and it compiles down to
without any error messages in webpack watch log.
Whereas the second example from that page compiles as
which is expected.
Does it mean the plugin does not perform static checks?