TypeScript 捆绑不适用于外部模块

TypeScript bundling not working for External Modules

我有一个示例 TypeScript 代码,我正在尝试 捆绑 多个 ts/tsx 文件使用 打字稿编译器(tsc).

代码如下:

文件:ISample.ts

    class ISample{
        constructor(public value:string){
        }
    }
    export = ISample;

文件:Sample.ts

    import ISample = require('./ISample');

    class SampleImpl{
        value: ISample;
        constructor(sample:number){
            this.value = new ISample(sample+'');
        }
    }

文件:tsconfig.json

    {
        "compilerOptions": {
            "module": "amd",
            "noImplicitAny": true,
            "removeComments": true,
            "preserveConstEnums": true,
            "jsx": "react",
            "outFile": "./dist/bundle.js",
            "target": "es3",
            "listFiles": true,
            "sourceMap": false
        },
        "files": [
            "./src/Sample.ts",
            "./src/ISample.ts"
        ]
    }

当我运行命令时:

    tsc
生成了

bundle.js但是完全是空白

观察:

  1. 当我将代码移动到内部模块

  2. 时,问题没有出现
  3. 当我省略 import/require 语句并使用 ISample[= 的声明时,问题也不会发生52=] class,但在那种情况下 bundle.js 不包含 ISample class 的代码

知道为什么会这样吗?

目前不支持:Suggestion: multi-file external modules

有一组解决方法,例如Compile TypeScript with modules and bundle to one file