Constructor return type annotations produce invalid JS syntax
rtsao opened this issue · 1 comments
rtsao commented
Source:
class Foo {
constructor(): Foo {
return this;
}
}
Transformed (actual):
class Foo {
constructor(): {
return this;
}
}
Transformed (expected):
class Foo {
constructor() {
return this;
}
}
Reproductions:
- TS: https://sucrase.io/#transforms=typescript&code=class%20Foo%20%7B%0A%20%20constructor()%3A%20Foo%20%7B%0A%20%20%20%20return%20this%3B%0A%20%20%7D%0A%7D
- Flow: https://sucrase.io/#transforms=flow&code=class%20Foo%20%7B%0A%20%20constructor()%3A%20Foo%20%7B%0A%20%20%20%20return%20this%3B%0A%20%20%7D%0A%7D
alangpierce commented
Hi @rtsao , sorry for the delay, and thanks for reporting! That syntax is actually invalid in both TypeScript and Flow, so I'd normally call it out of scope for Sucrase, but I understand the error is pretty confusing, and it's easy to fix in Sucrase, so I'll put up a PR to fix.