typescript 0.9 single output file and order of dependencies

Topics: General
Aug 28, 2013 at 9:41 AM
Hi,

I understand that in Typescript 0.9 all files somehow reference each without explicit reference paths. But if i add the setting to compile to single file the order in which the ts files from the project are concatenated does not seem to respect the order of dependencies between files.

simple example: b.ts defines an enum type, and a.ts uses this enum, but the order in the output file is a.ts followed by b.ts, which is clearly wrong.

There doesn't seem to be any official documentation on this.
Any help?
Coordinator
Aug 28, 2013 at 8:02 PM
If your example has a.ts referencing b.ts but not vice versa, does it put b before a in the output? Curious if it's related to circular or implied dependencies at all.
Aug 28, 2013 at 8:17 PM
Edited Aug 28, 2013 at 8:19 PM
Hi,

is an implied dependency.
If Typescript compiler already knows the implied references between files, why does it fail to put the output in correct order?
I tried creating class inheritance, class A in file1 and class B extends A in file2.

The output is still in reverse order.
Aug 29, 2013 at 4:09 AM
The last time I followed a discussion on this topic the conclusion was that TS will not guarantee the correct order of file1 and file2 in the output in regards to the class hierarchy.
The order is solely determined by the processing of <reference> tags which can be tricky to unmanageable in more complex scenarios. See ticket #913.

A common approach is to have a single file as entry-point for the compiler that defines all files in the project in the correct order via reference tags. Individual files in the project all reference this 'master' file. (This approach is explained in more detail in the comments to the ticket linked above.)

I've read that Visual Studio has recently introduced a new behavior where all TS files in a project automatically reference each other. It would be interesting to hear from VS users whether VS will take care of the correct order when compiling to a single output file.

Not sure if there have been other changes in regards to the ordering issue in recent releases, maybe @jonturner can clarify.

Personally, I would like to see the TS team describe the recommended approach for a project setup that uses the pattern of one class per file, with the entire project being compiled into one output file.

After the recent changes in the compiler (cleanup of command line switches) and VS, I assume that this is not something that will be handled inside the compiler, but is rather expected to be dealt with on tool level. Again, I would appreciate the TS team commenting hereon as well.
Aug 29, 2013 at 7:11 AM
Thank you for the reply,

I discovered googling that other developers use this trick with the file that defines all the references in the project.
I am trying this approach, and i notice that the reference comments are always included in the middle of the output file not grouped on start, and my comments are not always honored.
The compiler is behaving very strange...I remember that I modified the ts sources in the past to cleanup the output file....
Typescript roadmap follows the tradition at Microsoft, take Entity Framework: a great tool in its core, but very slow in improvement of small things for developers, and unusable in its Visual Studio Add-in.
Aug 30, 2013 at 4:48 AM
My guess is that the compiler collects all reference tags of the current file, then recurses into these files and includes the output before including the actual contents of the current file (including the original reference tags).

Preserving comments in the output is a very nice feature IMHO - it appears that there are efforts to have readable JavaScript output that could also be used without TS sources. Personally, I like that the code generated by the compiler is very slick.

I do hope that the focus of the TS team now shifts to making a developer's life easier after what appeared to be major internal changes in the compiler in the 0.9 release.