Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

decorators in object literals not working

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:3
  • Comments:20 (9 by maintainers)

github_iconTop GitHub Comments

hb20007commented, Dec 28, 2020

This issue still exists. Even when this setting is on in my IDE (VS Code):

Experimental decorators enabled

I get the following errors:

Screenshot with errors

evisongcommented, Nov 6, 2017

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.


Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found