3

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

1 Answer 1

1

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!

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Steve, I hope it will as the workaround is quite annoying. (Compile -> Manually add refs > Remove --declaration flag so next compile doesn't overwrite -> Run -> Re-add --declaration flag and repeat process with any changes to library). I might try to set up a better workaround by prepending a _dependencies.ts file post compile.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.