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

Type incorrect on decorator metadata when unioning null #3371

Closed
gregarcara opened this issue Jan 26, 2022 · 3 comments
Closed

Type incorrect on decorator metadata when unioning null #3371

gregarcara opened this issue Jan 26, 2022 · 3 comments

Comments

@gregarcara
Copy link

gregarcara commented Jan 26, 2022

Describe the bug

When unioning null the type on the decorator metadata is Object when for example it is string | null the type should be string. This is causing issues when using type-graphql and typeorm. This is similar to #2703

Input code

import 'reflect-metadata';

const COL_KEY = Symbol('col');

const column = () => {
    return (object: any, key: string) => {
        Reflect.defineMetadata(COL_KEY, 'value', object, key);
    };
};

class User {
    @column() currency!: string | null;
}

console.log(Reflect.getMetadata('design:type', User.prototype, 'currency'));

Config

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

Playground link

https://play.swc.rs/?version=1.2.133&code=H4sIAAAAAAAAA02PwWrDMAyG73kK7WQH0jxAQstg9NSNwUYPOw3XUUM2xw6yPDBd3312k5TpZsn6v0%2FDODliEIRng5o3I7LqFCvRFoV21jM8vT5%2FHvYfsIX3OJ6ckUI7I8r7PL3CaNNYlrDdwaWAVIQcyIJ0p6%2BU2oCysYJvjA14psH2%2F77mepvpdYfnweLL4iAXdAXiR5mAooI57xaVDPLqtS2u2cUo7%2BHokZbYx9krSelAhFbHhxUOv2CDMWlxvsEZrI3r5WrRI98VRId%2B6G3Dccr8DKgncuxyI4mt4aIs2z%2FsblknTAEAAA%3D%3D&config=H4sIAAAAAAAAA02OMQ7CMAxF7%2BK5A7CRFVa4g5WYipLEke1KRFXuTiKEyvaH9%2FT%2BBot6cBsUFCUZS2s2fIMDq4XUy7MYTBDIs6CxKDiTldoEJpj1wZKGFWlGX68%2F6gv9aTcyDGi42ygzWc%2BQng7Hc0%2B8iMolouodE%2B2ZxGGNNBrjUBc8p8R5UWjtA3yjCke%2FAAAA

Expected behavior

[Function: String] is output

Actual behavior

[Function: Object] is output

Version

@swc/core: 1.2.133

Additional context

Used #2703 as a reference.

@kdy1
Copy link
Member

kdy1 commented Jan 27, 2022

This requires typesystem

@kdy1 kdy1 removed the C-bug label Jan 27, 2022
@kdy1 kdy1 added this to the Blocked by type checker milestone Mar 12, 2022
@kdy1
Copy link
Member

kdy1 commented Jan 30, 2024

Closing as the 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

3 participants