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

No type metadata for decorated properties with user defined types #5360

Closed
ItamarMalka opened this issue Aug 1, 2022 · 3 comments
Closed

Comments

@ItamarMalka
Copy link

Describe the bug

some ORM libraries e.g sequelize depend on decorated property metadata in order to resolve the model properties for it.
When using swc as a transformer they fail because swc transforms any type into a "design:type": Object even for simple types e.g type a = string / type b = '123' | '456' etc...

Input code

type someType = string;
@decorator
function someDecorator(): string {
    return 'some decorator';
}

class Foo {
    @someDecorator()
    someProp: someType
}

console.log(returnType);

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "decorators": true
    },
    "transform": {
      "legacyDecorator": true,
      "decoratorMetadata": true
    },
    "target": "es2019"
  },
  "module": {
    "type": "commonjs"
  },
  "minify": false,
  "isModule": true
}

Playground link

https://play.swc.rs/?version=1.2.222&code=H4sIAAAAAAAAAyupLEhVKM7PTQ0BMWwVikuKMvPSrbkcUlKT84sSS%2FKLuNJK85JLMvPzwMpcYMIamlZQxQrVXApAUJRaUlqUp6AOUqUA161uzVXLxZWck1hcrOCWnw9V64BmFFgQJBZQlF9gBXcPWGt%2BXnF%2BTqpeTn66BsQKkIymNQDlWb%2BOuQAAAA%3D%3D&config=H4sIAAAAAAAAA02NSw7CMAxE7%2BJ1F8COrNn2EFbiVKnyk%2B1KRBV3J2lBsLM8b97ssIoFs0NFFuJxScuKTzCgrZJYDlVhAke2MGphAaO80WsCZcziC6fRirSgbY8vdUJ%2FtZkUHSr%2B2sgLaZ8huV2ud%2BivVNwWadjGdI9sSankVY4w5OAbGI9RujjI%2FKEP3xujmtUiyAAAAA%3D%3D

Expected behavior

same as tsc output:

__decorate([
    someDecorator(),
    __metadata("design:type", String)
], Foo.prototype, "someProp", void 0);

Actual behavior

_decorate([
    someDecorator(),
    __metadata("design:type", typeof someType === "undefined" ? Object : someType)
], Foo.prototype, "someProp", void 0);

Version

1.2.222

Additional context

The said example works properly when the type is inlined into the property, maybe there is a way to evaluate the type metadata in the same manner?

@kdy1 kdy1 added this to the Blocked by type checker milestone Aug 2, 2022
@kdy1 kdy1 removed the C-bug label Aug 2, 2022
netroy added a commit to n8n-io/n8n that referenced this issue May 26, 2023
netroy added a commit to n8n-io/n8n that referenced this issue May 26, 2023
netroy added a commit to n8n-io/n8n that referenced this issue May 26, 2023
@sq-ricardo-pereira

This comment was marked as spam.

@kdy1
Copy link
Member

kdy1 commented Jan 30, 2024

Closing as the stc is now abandoned. #571 (comment)

@kdy1 kdy1 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 30, 2024
@swc-bot
Copy link
Collaborator

swc-bot commented Feb 29, 2024

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 Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

4 participants