Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decorator design:type for union types #2461

Closed
hcesar opened this issue Oct 18, 2021 · 1 comment · Fixed by #3057
Closed

Decorator design:type for union types #2461

hcesar opened this issue Oct 18, 2021 · 1 comment · Fixed by #3057
Labels
Milestone

Comments

@hcesar
Copy link

hcesar commented Oct 18, 2021

Describe the bug
When you have a union type on a decorated property the design:type is set to void 0.
TSC would set the type to Object instead.

Input code


class Xpto {
  @Decorator()
  prop!: string | number;
}

function Decorator() {
  return function (...args) {};
}

Config

{
  "module": {
    "type": "commonjs"
  },
  "jsc": {
    "target": "es2018",
    "parser": {
      "syntax": "typescript",
      "decorators": true,
      "dynamicImport": false
    },
    "transform": {
      "legacyDecorator": false,
      "decoratorMetadata": true
    }
  }
}

Current behavior

TSC:

__decorate([
    Decorator(),
   __metadata("design:type", Object)
], Xpto.prototype, "prop", void 0);

SWC:

Reflect.metadata("design:type", void 0)

Expected behavior
SWC:

Reflect.metadata("design:type", Object)
@hcesar hcesar added the C-bug label Oct 18, 2021
jameslnewell added a commit to jameslnewell/swc that referenced this issue Dec 17, 2021
@kdy1 kdy1 added this to the v1.2.122 milestone Dec 20, 2021
kdy1 pushed a commit that referenced this issue Dec 20, 2021
…3057)

swc_ecma_transforms_proposal:
 - Use `Object` for `null`/`undefined`.
 - Fix the type for union types. (Closes #2461)
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 20, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3 participants