Skip to content

[Bug]: Decorators Conflict With Function Overloading #9220

@daniel-nagy

Description

@daniel-nagy

Bug Report

Current Behavior

When using @babel/plugin-proposal-decorators alongside @babel/preset-typescript function overloading does not work.

TypeError: Duplicated element (nameOfOverloadedClassMethod)

This is the transpiled output:

{
  kind: "field",
  key: "nameOfOverloadedClassMethod",
  value: void 0
}, {
  kind: "field",
  key: "nameOfOverloadedClassMethod",
  value: void 0
}, {
  kind: "method",
  key: "nameOfOverloadedClassMethod",
  value: function value(_bar) {
    // actual body of method
  }
}

Input Code

class Foo {
  nameOfOverloadedClassMethod(bar: string);
  nameOfOverloadedClassMethod(bar: number);
  nameOfOverloadedClassMethod(bar) {
    // some implementation
  }
}

Expected behavior/code

The overloaded methods are removed when transpiling before decorators mangle the class.

Babel Configuration (.babelrc, package.json, cli command)

{
  loader: 'babel-loader',
  options: {
    presets: [
      [
        '@babel/preset-env',
        {
          modules: false,
          useBuiltIns: 'usage'
        }
      ],
      '@babel/typescript'
    ],
    plugins: [
      ['@babel/plugin-proposal-decorators', {
        decoratorsBeforeExport: true
      }],
      '@babel/plugin-proposal-class-properties',
      '@babel/plugin-proposal-object-rest-spread',
      '@babel/plugin-transform-runtime',
      'angularjs-annotate'
    ]
  }
}

Environment

  • Babel version(s): v7.2.0
  • Node/npm version: Node 9.11.2
  • OS: OSX 10.14.1
  • Monorepo: no
  • How you are using Babel: loader

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: plugin orderingoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions