Typescript declaration files do not contain the reference paths. Is this ok?

Topics: General
Feb 21, 2013 at 6:26 PM
Typescript declaration files do not contain the reference paths. Is this ok?
How to force the compiler to include the reference paths in declaration files?
Feb 22, 2013 at 9:52 AM
Try with --comments option of tsc compiler.
Feb 22, 2013 at 12:05 PM
I added the --comments option, but does not change the output....
Coordinator
Feb 22, 2013 at 7:17 PM
I'm not sure exactly what you're trying to do. Are you automatically generating the declaration files? What isn't being included that you want to force?
Apr 5, 2013 at 3:09 PM
Hi Jon,

I think the intention is that the declaration file should contain any reference comments that point to dependencies, for example... if I manually wrote a declaration file for a jQuery plugin, I would add the following to the top of the d.ts file:
///<reference path="../jquery/jquery.d.ts" />
My plugin declaration now has its dependencies clearly labelled, rather than relying on the consumer to add both jquery.d.ts and myplugin.d.ts to their TypeScript file.

Does this help to clarify?
Apr 5, 2013 at 8:02 PM
Hi,

This is exactly the issue I'm experiencing. As ursuletzu stated, the --comments flag is ignored for declaration files and this is a problem because manually adding the references will get overwritten on next build.
Developer
Apr 6, 2013 at 12:11 AM
Could you create a work item with the exact steps to reproduce the issue? This is the behavior I see on 0.8.3 as well as our latest bits:
C:\test>type repro2.ts
/// <reference path='file2.ts'/>
class C {
       blah(): void {}
}

C:\test>tsc --declaration repro2.ts

C:\test>type repro2.d.ts
/// <reference path="file2.d.ts" />
declare class C {
    public blah(): void;
}

C:\test>tsc --declaration -c repro2.ts

C:\test>type repro2.d.ts
/// <reference path="file2.d.ts" />
declare class C {
    public blah(): void;
}
Oct 31, 2013 at 11:57 PM
I want the opposite of this feature. Declarations files with references to file paths are terrible. It makes the declarations file less portable because all of your project structures have to be the same.

My situation is this: I have 3 projects A, B, and C. B is a collection of typescript files that are shared between projects A and C. B is dependent upon JQuery which means it has a /// <reference path="JQuery.d.ts" /> reference. However, projects A and B are not structured the same which means I have to alter project B's declarations file when I add it to project A. I have to change the reference to something like /// <reference path="../../JQuery.d.ts" >. This makes automating my build process super annoying because I have to change the reference in my declarations file. The same goes for when I import the declarations file to project C.

A few more details about my situation. Project B is just a collection of Typescript files. It includes one Typescript file, B.all.ts, that simply references all the other Typescript files in the project. Like:
/// <reference path="file1.ts" >
/// <reference path="file2.ts" >
etc.

Then to build the declarations file I wrote a command that does this: tsc.exe -d -out $(ProjectDir)\B.all.js --target ES5 $(ProjectDir)\B.all.ts. The result is a declarations file for all the objects in project B. Which is great. Except for the local references to JQuery.d.ts. So as an attempted work around I added this to B.all.ts: interface JQuery {}. The resulting definitions file includes this new definition now: interface JQuery {}. Which makes the declarations file compile unfortunately, the references to JQuery.d.ts are still included as well.

Is there any way to make the declarations file remove the local references to JQuery.d.ts? I'm using Typescript 0.9.1.1.
Dec 30, 2013 at 11:44 PM
Bumping ScottJet's comment. This makes publishing a library really unpleasant, since I am now placing project structure constraints on my consumers. As of 0.9.5.0, I still can't see a way to disable this. Please help us!