microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.19k stars 12.38k forks source link

Experimental Decorators don't work in `export` statements #39596

Open Domiii opened 4 years ago

Domiii commented 4 years ago

TypeScript Version: JavaScript + ESNext

Search Terms: export+experimental+decorators+export

Code

export default
@x
class A {
}

[❌ ] The above does not work.

@x
class A {}

export default A;

[👌 ] It does work when going with the old syntax, that is splitting export statement and class expression. I.e. this works fine:

Expected behavior:

The syntax should be valid, according to @babel/plugin-proposal-decorators, which is also in line with tc39, as discussed here.

Actual behavior:

The first @ raises:

Expression expected. ts(1109)

Playground Link:

https://www.typescriptlang.org/play/?target=99&ts=4.0.0-dev.20200714&useJavaScript=true#code/KYDwDg9gTgLgBAE2AMwIYFcA2MBQABGVAcwAoByYAYwFsBaUMTVASwDtgoyBKfGYaxqj7kAPAmYA3AHwiA9OOncclJgGdVcALIBPAMIQBcUH1YINAZUzNqcAN44AvkA

Related Issues:

I previously posted on VSCode issues and was sent here:

RyanCavanaugh commented 4 years ago

The decorators implemented in TS are the "experimental" decorators that effectively predate the current TC39 proposal, which has not reached Stage 3 yet.

trusktr commented 2 years ago

OP must be working around with Babel: separating the export statement so TS doesn't have an error, then @babel/typescript can compile it (I'm doing this too).