microsoft / microsoft/TypeScript

Experimental Decorators don't work in `export` statements

Open
#39,596 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Suggestion Waiting for TC39
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

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:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked TypeScript Playground and compare the failing export default @x class A {} example with the working split declaration. Trace how the compiler handles decorators before exported classes, then add coverage showing the expected syntax is accepted without regressing the existing form.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.