TypeScript: decorators in object literals not working
From @pascalopitz on November 19, 2015 11:43
I am getting a parsing error for decorators on object literal properties. My jsconfig.json looks like this:
{
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"experimentalDecorators": true
}
}
This code compiles okay in babel 5.8.12 using the “es7.decorators” extension. Can I somehow make this work?

Copied from original issue: Microsoft/vscode#201
About this issue
- Original URL
- State: open
- Created 9 years ago
- Reactions: 5
- Comments: 20 (9 by maintainers)
This issue still exists. Even when this setting is on in my IDE (VS Code):
I get the following errors:
Hi, team, we’ve been heavily used ES decorators, especially decorators for object literals in our products, currently any code after blocks decorated by such decorators, could not be parsed correctly by VSCode; it keeps prompting
[js] ';' expected.or[js] Declaration or statement expected., which seem annoying.With some search, we found this issue, however a year has passed since last update of the issue. ES standards are evolving slower than we expected but babel-plugin-transform-decorators-legacy is still popular. Seems a lot of JS open source libs depend on this legacy decorators for object literals.
Is it possible for TS or VSCode to add a special setting to allow the decorators for object literals in JS code (e.g.
experimentalDecoratorsForObjectLiterals), regardless the ES standard? It’s ok to keep the legacy/non-standard warnings, but for minimal the code after the decorated blocks should be parsed correctly.Thanks.
VSCode uses TS to power the JS/TS language service. If the feature is supported in TS, it will light up in future VSCode versions.
Keep in mind that decorators are currently a stage 2 proposal TC39, and not a ratified feature. we do plan on revisiting our decorator support soon, and implementing the new proposal. once we do that, we should have a clear resolution for this feature.