parliament
parliament

Reputation: 22914

Typescript declaration file doesn't include other declaration file references

I built a TypeScript library that is the "Core" to my application (call it Core.ts) using internal modules and a single class per file approach compiled to a single output file(Core.js). I added --declaration flag to compiler and it generates the declaration file (Core.d.ts). Problem is, this generated declaration file didn't include the references to other declaration files originally included in the compilation. Once I add the generated Core.d.ts to my project I get something like 1k errors about undefined JQuery, Backbone, etc... coming from that file.

I have the comments flag set to true and it generated the comments and references in Core.js but stripped them all away for Core.d.ts

If I look at other definition files I grabbed from Definitely Typed some do include references to other definition files so this seems like a bug that the compiler is stripping them away despite comments flag being set to true.

Please advise.

Seems this issue has been encountered but never looked into:

https://typescript.codeplex.com/discussions/434018

Upvotes: 3

Views: 1490

Answers (1)

Fenton
Fenton

Reputation: 250922

It sounds like you are expecting Core.d.ts to include the definitions from jquery.d.ts and backbone.d.ts but I think conceptually the TypeScript compiler expects you to reference all three:

///<reference path="jquery.d.ts" />
///<reference path="backbone.d.ts" />
///<reference path="Core.d.ts" />

A typical example of this are jQuery plugins - each definition file contains the definition of the plugin, but not of jQuery, so you need to reference both jquery.d.ts and jquery.someplugin.d.ts.

Update

Actually - I think you are just expecting the reference comment to be included in Core.d.ts - this makes more sense. I'm going to comment on the bug on CodePlex that you linked to, maybe it will wake the discussion up!

Upvotes: 1

Related Questions