decorators in object literals not working
See original GitHub issueFrom @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
Issue Analytics
- State:
- Created 8 years ago
- Reactions:3
- Comments:20 (9 by maintainers)
Top Results From Across the Web
NG1001: Decorator argument is not an object literal - Angular
To make the metadata extraction in the Angular compiler faster, the decorators @NgModule , @Pipe , @Component , @Directive , and @Injectable accept...
Read more >TypeScript: get wrong object when use Property Decorator
The TypeScript documentation says that instance property decorators receive the class prototype as the first argument. As a result, inside your ...
Read more >Documentation - Decorators - TypeScript
Decorator Evaluation Parameter Decorators are applied for the constructor. Class Decorators are applied for the class.
Read more >Using Object Literals as Classes - ES Discuss
I think object literal operators fail at being usable with class libraries specifically because they are here to replace them, not work in...
Read more >Content Types - ESBuild
For example, without this flag the object literal {x: x} will become {x} and the ... But such code will not work with...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.