Adrian Rosca
Adrian Rosca

Reputation: 7432

How do I handle TypeScript type definitions across many Visual Studio (2013) projects?

I develop quite a large application that consist of a lot of javascript projects (VS projects). Now, I'm considering to convert the JS step by step to TypeScript.

I use a number of external libraries, such as JQuery, Knockout Js, etc and downloaded their d.ts files to one of the projects. Each of my project in turn will have to generate its own d.ts file. I found the "generate source map" setting in VS, so I got that one.

I realize that I pretty soon will have a huge amount of d.ts files that would need to be included in almost all projects. I can beforehand see that this will be a huge problem. I googled around a bit but maybe I'm searching it wrong. Cannot find a good approach on this.

As I see it, the best solution would be if all projects got their type definitions from some kind of common type definitions folder. Is that somehow possible?

Upvotes: 0

Views: 1208

Answers (1)

Judah Gabriel Himango
Judah Gabriel Himango

Reputation: 60061

First, remember that .d.ts files (hereafter type declaration files) are only for type definitions for JavaScript code. If you're writing your code in TypeScript, there will be no declaration files. There will only be .ts.

In a pure TypeScript project, you'll typically have all your code in TypeScript, and the only type declaration files you'll have are the 3rd party dependencies, e.g. jquery.d.ts, bootstrap.d.ts, etc.

If your project is pure TypeScript, I'd manage all those type declaration files just using NuGet. Install your dependencies using NuGet, and install the type declaration files using NuGet. NuGet can then manage dependencies for your entire solution.

If your project is not pure TypeScript, that is, you're converting it piece at a time, and you create type declaration files for your JavaScript code that is not yet ported to TypeScript, then I'd suggest adding your type declarations in a single file and linking that file into all the projects that need it. Then you have a single place for all your type declarations.

One other note: source maps and .d.ts files have nothing to do with each other. Source maps are JSON files that map TS line of code to JS line of code. This effectively lets you debug your TypeScript in the browser, if you so choose.

Upvotes: 3

Related Questions