如何避免TS三斜杠指令中的丑陋输入

时间:2019-03-22 07:21:24

标签: typescript types

我有一个嵌套的订单结构。如果现在使用三斜杠指令,则取决于这样的文件,我的数据路径将很长:

/// <reference path="../../../../global.d.ts" />

我现在问自己的问题是否有办法阻止它执行此操作?

1 个答案:

答案 0 :(得分:2)

由于TypeScript 1.5(请参见“轻巧,可移植的项目” 部分),语法/// <referenceconfiguration file tsconfig.json取代。

Node.js的示例:

// tsconfig.json
{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "outDir": "dist"
  },
  "exclude": [
    "dist",
    "node_modules"
  ]
}

tsconfig.json文件中,可以定义includeexclude属性。定义exclude属性后,默认情况下将包括所有其他属性。现在您的项目看起来像:

- project-directory/
    |- dist/
    |- node_modules/
    |- src/
        |- global.d.ts
        |- path/to/other/files.ts
    |- tsconfig.json