Closed sgodwin424 closed 8 years ago
@sgodwin424 does it only occur when returning an empty string?
It doesn't seem to matter what the string is, it will cause the error. However, the following examples won't:
function foo(): string
{
let a = '';
return a;
}
function foo(): number
{
return 22;
}
ok will try and fix it later. For now you can work around this by using a pragma:
// @fixme typecheck: ignore statement because of bug #68
function foo(): string {
return '';
}
I found another scenario in which it occurs:
foo.js
class Foo
{
constructor()
{
this.ret = '';
}
MyFunction(): string
{
return this.ret;
}
}
This is a bit unrelated to string literals, since this will throw an error regardless of what property of this
you are returning.
SyntaxError: C:/Users/Scott/Documents/GitHub/test/foo.js: Function did not return a value, expected string
←[0m 6 | ←[32m}←[39m
7 |
> 8 | MyFunction←[94m←[1m(←[22m←[39m←[94m←[1m)←[22m←[39m←[1m:←[22m string
| ^
9 | ←[32m{←[39m
10 | ←[36mreturn←[39m ←[36mthis←[39m←[1m.←[22mretsdfgsdfg←[1m;←[22m
11 | ←[32m}←[39m←[0m
With same stacktrace.
EDIT:
Just to clarify, this only happens with v3.3.0. v3.2.1 does not cause this problem.
I couldn't replicate this but I saw a possible way it could have happened and worked around it in 3.4.0. If it doesn't work, please let me know and I'll reopen this issue.
It solved the issue. Thanks.
The v3.3.0 update generates an error on the following code when running
node bar
:bar.js
foo.js
If I just do
babel foo.js --out-dir dist
, I can run the resulting filenode foo
without any errors.