1

Forgive me if I misunderstand, but I thought that if I used a tsconfig.json file at my project root, then I would no longer need to use any ///<reference path="..." /> tags in order to make my code compile. Am I wrong?

For example, I'm using AngularJS. My App.ts file looks something like this:

import SomeModule from './whatever/SomeModule';

angular.module('foo', [SomeModule.name]).run(...);

My tsconfig.json file looks (in part) like this:

{
    "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"
    ],
}

Notice that I have listed in my files array the path to the angular definition file. Also notice that I have the compileOnSave option set to false. Eventually I would like to use Browserify to compile and bundle all the code. But for now I just want to see if I can get it to compile with tsc.

But when I run tsc App.ts, I get an error that says "Cannot find name 'angular'." How do I make the TypeScript compile use the angular.d.ts file when compiling the code?

4

1 回答 1

2

由于正在指定文件,因此运行tsc App.ts将不起作用。按照文档中的说明进行操作:

使用 tsconfig.json

  • 通过在没有输入文件的情况下调用,在这种情况下,编译器会从当前目录开始tsc搜索文件并继续父目录链。tsconfig.json
  • 通过tsc在没有输入文件和 -project(或仅 -p)命令行选项的情况下调用,该选项指定包含tsconfig.json文件的目录的路径。

在命令行上指定输入文件时,将忽略 tsconfig.json 文件。

资源

于 2015-06-15T18:21:19.943 回答