有没有办法告诉TypeScript使用某个文件(或一组文件)作为编译的所有内容的定义?
目前,我唯一的 Select 是在每个单独的TypeScript文件中添加类似的内容(看起来很笨重):
/// <reference path="DefinitelyTyped/requirejs/require.d.ts" />
有没有办法告诉TypeScript使用某个文件(或一组文件)作为编译的所有内容的定义?
目前,我唯一的 Select 是在每个单独的TypeScript文件中添加类似的内容(看起来很笨重):
/// <reference path="DefinitelyTyped/requirejs/require.d.ts" />
当使用TypeScript的内部模块系统时,代码中可以避免任何<reference>
个标记.我个人这样做是因为我不想在代码中编码路径(真实的或绝对的),因为我不断地移动东西.
一种方法是确保所有必需的声明文件和TypeScript源文件都在编译时作为参数传递给编译器.
使用gulp和gulp-typescript可以简化这项任务.您可以将gulp-typescript
中的noExternalResolve
设置为true,并创建占用您所有时间的gulp 任务.d、 ts文件以及源代码,并通过管道将其传递给编译器.当您将tsd拉入堆栈时,只需传递tsd.d.ts
文件,该文件包含对通过tsd
安装的所有其他定义文件的引用.
UPDATE for TypeScript >= v1.5: you can use a tsconfig.json file, and the compiler will get the ordering of the classes right. This removes the need to use gulp-typescript
alltogether. You can either chose to have all files explicitly listed in the tsconfig.json
file, or completely leave out the files
property to include all *.ts/*.tsx
files within the directory the tsconfig.json
resides (including all subfolders).
样本tsconfig.json
可能看起来像:
{
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"lib": [ "es5", "es2015.promise", "dom" ]
},
"include": [
"src/**/*.ts"
]
}