Why Does This Typescript Output “[Class] is not a constructor.”?

后端 未结 12 1262
清歌不尽
清歌不尽 2021-01-17 07:55

I\'m working in typescript 1.5 in visual studio. I have a main class called app.ts, and another called FizzBuzzManager.ts. I can\'t figure out what is wrong with this code,

12条回答
  •  终归单人心
    2021-01-17 08:38

    In my case I had the problem when I used babel with preset-env to compile TS-sources.

    Works:

    {
        "presets": ["@babel/typescript"],
        "plugins": [
            "@babel/proposal-class-properties",
            "@babel/proposal-object-rest-spread",
            "@babel/plugin-transform-runtime"
        ],
        "ignore": ["node_modules", "src/test"]
    }
    

    Wrong:

    {
        "presets": [
            "@babel/typescript",
            [
                "@babel/preset-env",
                {
                    "targets": {
                        "browsers": [
                            "last 2 Chrome versions",
                            "last 1 Safari versions",
                            "last 1 Firefox versions"
                        ]
                    }
                }
            ]
        ],
        "plugins": [
            "@babel/proposal-class-properties",
            "@babel/proposal-object-rest-spread",
            "@babel/plugin-transform-runtime"
        ],
        "env": {
            "node": {
                "presets": [
                    [
                        "@babel/preset-env",
                        {
                            "targets": {
                                "esmodules": true,
                                "node": "current"
                            },
                            "modules": "auto"
                        }
                    ]
                ]
            }
        },
    
        "ignore": ["node_modules", "src/test"]
    }
    

提交回复
热议问题