This project is read-only.

Ability to reference other file just for type checking

Topics: Language Specification
Oct 3, 2012 at 1:42 PM

Right now, if I understand well, we could use the <reference> tag to tell the compiler we want him to check for the reference and resolve recursively all its dependency before actually compile the source code.

The problem is that writing:

/// <reference path="./othersourcecode.ts" />

Will also import "othersourcecode.ts" content inside the compiled javascript.

I'm looking to know if there is a way we could let the compiler know that the current .ts file needs others to be parsed and resolved but not imported in the compiled content.

something like:

/// <reference path="./othersourcecode.ts" reference-only="true" />

Would be nice but i'd probably suggest having a compiler option you can use so that the source code could be compiled in both way if you want. Something like:

tsc --out file.js --dependency-inclusion false SourceFile.ts

Oct 3, 2012 at 4:20 PM

It seems you are correct based on the language spec (see "9.1.1 Source Files Dependencies").  This behavior is incredibly unexpected to me given past experience utilizing the <reference> element in JavaScript files for Intellisense purposes.  I would agree that there either needs to be a way to prevent that dependency from being compiled in, or else a user should be forced to utilize `import` statements instead of having implicit dependency resolution at compile-time based on these <reference> elements.

I am very disappointed in this one.  I would consider this a bug, personally, but it is clearly intended based on its presence in the language spec. =(

Oct 3, 2012 at 4:23 PM

This is very needed. Our app already has a system in place for managing JS file dependencies at runtime and tsc is completely incompatible with it. The ability to reference JS files for type checking without having them compiled into the same JS file is necessary to fix this.

Oct 3, 2012 at 7:40 PM

I actually found, reading the compiler code, that if the --out file.js argument is not present than we get the expected behavior.