Javascript 如何在不使用任何引用的情况下编译TypeScript
如果我误解了,请原谅,但我认为如果我在项目根目录中使用了Javascript 如何在不使用任何引用的情况下编译TypeScript,javascript,angularjs,typescript,tsd,Javascript,Angularjs,Typescript,Tsd,如果我误解了,请原谅,但我认为如果我在项目根目录中使用了tsconfig.json文件,那么我就不再需要使用任何//标记来编译代码。我错了吗 例如,我正在使用AngularJS。我的App.ts文件如下所示: import SomeModule from './whatever/SomeModule'; angular.module('foo', [SomeModule.name]).run(...); { "compileOnSave": false, "compilerO
tsconfig.json
文件,那么我就不再需要使用任何//
标记来编译代码。我错了吗
例如,我正在使用AngularJS。我的App.ts
文件如下所示:
import SomeModule from './whatever/SomeModule';
angular.module('foo', [SomeModule.name]).run(...);
{
"compileOnSave": false,
"compilerOptions": {
"target": "es5",
"module": "commonjs"
},
"filesGlob": [
"./www/**/*.ts",
"./typings/**/*.ts"
],
"files": [
/* a bunch of files omitted for brevity*/
"./typings/angularjs/angular.d.ts"
],
}
我的tsconfig.json
文件(部分)如下所示:
import SomeModule from './whatever/SomeModule';
angular.module('foo', [SomeModule.name]).run(...);
{
"compileOnSave": false,
"compilerOptions": {
"target": "es5",
"module": "commonjs"
},
"filesGlob": [
"./www/**/*.ts",
"./typings/**/*.ts"
],
"files": [
/* a bunch of files omitted for brevity*/
"./typings/angularjs/angular.d.ts"
],
}
请注意,我在文件数组中列出了角度定义文件的路径。还要注意,我将compileOnSave
选项设置为false。最后,我想使用Browserify来编译和捆绑所有代码。但现在我只想看看我是否能用tsc
编译它
但是,当我运行
tsc App.ts
时,我会收到一个错误,上面写着“找不到名称'angular'。“在编译代码时,如何使TypeScript编译使用angular.d.ts
文件?运行tsc App.ts
将无法工作,因为指定了一个文件。按照文档中的说明进行操作:
使用tsconfig.json
- 通过在没有输入文件的情况下调用
,在这种情况下,编译器将从当前目录开始搜索tsc
文件,并继续搜索父目录链tsconfig.json
- 通过调用
而不使用输入文件和-project(或-p)命令行选项,该选项指定包含tsc
文件的目录的路径tsconfig.json
阅读文档-但愿我想到了这一点!:)