How to compile TypeScript without using any references whatsoever

1.4k views Asked by At

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?

1

There are 1 answers

1
David Sherret On BEST ANSWER

Running tsc App.ts won't work because a file is being specified. Follow the instructions from the documentation:

Using tsconfig.json

  • By invoking tsc with no input files, in which case the compiler searches for the tsconfig.json file starting in the current directory and continuing up the parent directory chain.
  • By invoking tsc with no input files and a -project (or just -p) command line option that specifies the path of a directory containing a tsconfig.json file.

When input files are specified on the command line, tsconfig.json files are ignored.

Source