This project is read-only.

references to other ts files and refactoring

Topics: Language Specification
Oct 7, 2012 at 11:24 PM

When writing complex javascript applications, sometimes you want to reorganise files, e.g. in a different folder structure...

But as soon as you start to reorganise things, references get broken:

suppose I move a ts file from the root folder to a subfolder, one needs to adjust in this file all references to other ts files in the root folder (e.g. jquery.d.ts becomes ../jquery.d.ts).

and all files containing a reference to the moved file, must also be changed from myfile.ts to subfolder/myfile.ts.

this might get very cumbersome especially in large scale applications. 

Oct 8, 2012 at 11:51 PM

Yes - this is a weakness of the ///<reference> approach, which trades off with the benefits of granular control over references.  One technique we've seen several projects use (and which we use in the TypeScript compiler codebase), is to have a single file be the "main" file for a project or folder, which includes all the references within that subproject.  Then each file in that subproject references the main file, and references from other subprojects need only reference the single main subproject reference file.  By doing there, the number of updates needed when a folder is moved is significantly reduced. 

We'll be looking more at layers for project structuring above the explicit ///<reference> mechanism in the future, and making it easier to rearrange code files on disk is a scenario we'll want to keep in mind.

Oct 10, 2012 at 5:28 PM

Can this technique be used for *.d.ts as well as for *.ts files, or only for *.d.ts files?

I tried the approach, but when I compile my solution, I get an error on one of the interface types , saying that it does not exist.

However, when execute Goto Declaration, it navigates perfectly to the interface.

Does the order of the references in main.d.ts matter? I have put all my *.d.ts files first (ordered alfabetically), than all *.ts files (again ordered alfabethically)

Does it matter whether main ends with .d.ts of .ts (I tried with main.d.ts) ?