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.

Redefine type always emit Object design:type

See original GitHub issue

Hello,

I have an issue, when I define a type like this: export type Uuid = string;

The emit type is: Object

The full case:

export type Uuid = string;

function Decorate() {
    return (target: any, prop: string): any => {
        const propertyType = Reflect.getMetadata("design:type", target, prop);
        console.log('propertyType', propertyType); // emit the Object type
    }
}

class Foo {
    @Decorate()
    public bar!: Uuid;
}

and my babel config:

// babel.config.js
module.exports = {
    presets: [
        ["@babel/preset-env", { "targets": { "node": "current" }, "modules": "commonjs" }],
        "@babel/preset-typescript"
    ],
    "plugins": [
        "babel-plugin-transform-typescript-metadata",
        ["@babel/plugin-proposal-decorators", { "legacy": true }],
        ["@babel/proposal-class-properties", { "loose": true }],
        "@babel/proposal-object-rest-spread"
    ]
};

I don’t know if it’s a defect coming from my Babel configuration, or a limitation from @babel/preset-typescript.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
leonardfactorycommented, May 28, 2020

I’ve used it exactly with the same setup, but not in production, where we reverted to TypeScript only (no babel, but same toolkit). With TypeORM you should be careful to use @Column(), even if for plain cases it still works and for advanced cases you still need to declare it manually anyway. With NestJS it works properly but TS support is still better.

0reactions
namnmcommented, May 28, 2020

@leonardfactory Thanks for the suggestion and quick reply. Just one more thing, I came here from the issue in the nestjs repo. I see that in the README this package can work well with Nest and TypeORM. Have you had any experiment project using this package for Nest? Is there any cautions that I need to take if I use this package in production with Nest and TypeORM?

Read more comments on GitHub >

github_iconTop Results From Across the Web

leonardfactory/babel-plugin-transform-typescript-metadata
Babel plugin to emit decorator metadata like typescript compiler - Issues ... Redefine type always emit Object design:type babel limitation Issues generated ...
Read more >
Typescript Reflect.getMetadata design:type returns Object ...
the test below is let's say the function Foo is a function based class,the typescript can't infer the Foo type so it emit...
Read more >
Documentation - tsc CLI Options - TypeScript
Flag Type Default ‑‑allowJs boolean false ‑‑allowUmdGlobalAccess boolean false ‑‑allowUnreachableCode boolean
Read more >
How to Emit Data in Vue: Beyond the Vue.js Documentation
Learn how to emit events from child components and nested child ... With all of this in mind, we're going to write an...
Read more >
Understanding TypeScript Configuration Options
Normally it will be used as type checking in JavaScript project. ... TypeScript will always parse in strict mode and emit use strict...
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