Part 1 - Custom decorators blocked in LWC

I'm trying to implement a custom decorator, very simple book example but getting LWC error in both LWC open source and LWC for salesforce,

LWC1100: Invalid decorator usage. Supported decorators (api, wire, track) should be imported from "lwc"

 export default class Logdecorator extends LightningElement {
         readonly(target, name, descriptor) {
            descriptor.writable = false;
            return descriptor;
          } }

export default class Decoratortest extends LightningElement {

  sum(a, b) {
    return a + b;


The document clearly says as per this link it supports ES2015-2019, since decorators part of ES2015 itself not sure why its explicitly blocked by framework and I also see the js spec test for throwing error if anything other than @api, @track, @wire to comfirm my assumption.

From LWC documentation site, https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.get_started_supported_javascript

Lightning Web Components JavaScript support includes:

ES6 (ECMAScript 2015)
ES7 (ECMAScript 2016)
ES8 (ECMAScript 2017)—excluding Shared Memory and Atomics
ES9 (ECMAScript 2018)—including only Object Spread Properties (not Object Rest Properties)

Part -2 - Dynamically creating web components is blocked as well.

Given that we can't create dynamically create LWC components, there is less chance to even try alternative solution similar to React Higher Order Components. So both solutions doesn't work in current framewor.

We are only left with basic funtion important and calling them as old fashion javascript not able to leverage modern features seems to be not fair for modern web component framework.


1 Answer 1


I am not really sure what you expect as answer to your Post (because there is basically no question). While your points are maybe true it is something nobody can change - Salesforce Development was always more restrictive than other places. You may want to look on its evolvement though (s-controls, visualforce, aura etc.) - you will see that things are still on its own getting better somehow (kind of ;) ). With Open Source LWC you are also free to actively work on the Framework via bugfixing or raising proposals for its development.

For Decorators: Salesforce focuses on finished Proposal (Stage 4) of the Spec. Decorators are still in Stage 2 which is the reason they don`t support them yet. Its on their roadmap but unlikely we will see it before decorators are officially in the spec.

For Dynamic Component Creation: It is explicitely wanted by them - you can see an example post on stackexchange here. They have a rfc already though which you may want to monitor / comment on

  • 2
    Thanks for the information, I belive LWC document site should callout clearly which features in ES2015 - 2019 are not supported (ex: Stag-2 is proposals).
    – realnumber
    Aug 3, 2019 at 3:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .