question-mark
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.

Babel decorator runtime helper errors for class with overloaded method

See original GitHub issue

Please paste the output of ember -v here

ember-cli: 3.7.1 node: 10.11.0 os: darwin x64

Please paste the output of tsc -v here

Version 3.3.3333

Please paste your tconfig.json and tslint.json or eslint.json (if applicable) below

My tsconfig.json

{ “compilerOptions”: { “target”: “es2017”, “allowJs”: true, “moduleResolution”: “node”, “allowSyntheticDefaultImports”: true, “noImplicitAny”: true, “noImplicitThis”: true, “alwaysStrict”: true, “strictNullChecks”: true, “strictPropertyInitialization”: true, “noFallthroughCasesInSwitch”: true, “noUnusedLocals”: true, “noUnusedParameters”: true, “noImplicitReturns”: true, “noEmitOnError”: false, “noEmit”: true, “inlineSourceMap”: true, “inlineSources”: true, “baseUrl”: “.”, “module”: “es6”, “experimentalDecorators”: true, “paths”: { “ember-typescript-overloads-decorators-bug/tests/": [ "tests/” ], “ember-typescript-overloads-decorators-bug/": [ "app/” ], “": [ "types/” ] } }, “include”: [ “app//*", "tests//", "types/**/” ] }

What are instructions we can follow to reproduce the issue?

git clone https://github.com/simonihmig/ember-typescript-overloads-decorators-bug
Reproduction Case

See the above reproduction repo.

Now about that bug. What did you expect to see?

Hit http://localhost:4200/ and see the default welcome page.

What happened instead?

Runtime error: Uncaught TypeError: Duplicated element (foo)

This happens when a TS class has at least one decorator and one overloaded method. Seems to be an issue with how the decorators and TS Babel plugins interact AFAICT.

The transpiled output of https://github.com/simonihmig/ember-typescript-overloads-decorators-bug/blob/master/app/controllers/application.ts looks like this:

let ApplicationController = (0, _decorate2.default)(null, function (_initialize, _EmberController) {
    class ApplicationController extends _EmberController {
      constructor(...args) {
        super(...args);

        _initialize(this);
      }

    }

    return {
      F: ApplicationController,
      d: [{
        kind: "field",
        decorators: [_service.inject],
        key: "router",
        value: void 0
      }, {
        kind: "field",
        key: "foo",
        value: void 0
      }, {
        kind: "field",
        key: "foo",
        value: void 0
      }, {
        kind: "method",
        key: "foo",
        value: function foo() {// dummy
        }
      }]
    };
  }, Ember.Controller);

So the overloaded foo method, which should affect only the typing, not the runtime code, causes multiple foo fields to be defined for the decorator runtime (@babel/runtime/helpers/esm/decorate), which then errors because of this.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lifeartcommented, Mar 14, 2019
0reactions
pzuraqcommented, Mar 4, 2019

See the latest revision of https://github.com/emberjs/rfcs/pull/440 for more details

Read more comments on GitHub >

github_iconTop Results From Across the Web

babel/CHANGELOG.md at main - GitHub
Babel is a compiler for writing next generation JavaScript. - babel/CHANGELOG.md at main · babel/babel.
Read more >
babel/plugin-proposal-decorators
@isTestable(true) class MyClass {} function isTestable(value) { return function decorator(target) { target.isTestable = value; }; }.
Read more >
Class constructor cannot be invoked without 'new' - typescript ...
At run-time I get this error: Class constructor Room cannot be invoked without 'new'. And the trouble in javascript:
Read more >
Babel Users' Guide - LLNL Software Portal
Syntax for specifying executable interface contracts; Special directives for large-scale parallel distributed programming (future). Babel enables true object- ...
Read more >
Babel: CHANGELOG.md - Fossies
babel -generator , babel-helpers , babel-parser , babel-plugin-proposal-decorators , babel-plugin-syntax-decorators , babel-runtime-corejs2 ...
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found