Interproject References in tsconfig.json · Issue #3394 · microsoft/TypeScript (original) (raw)
I've been thinking about project-level modularization with TypeScript, and I think the story is not nearly as good as what's available in other Microsoft languages like C# or VB. TypeScript urges you to have everything in a single folder structure (and in VS within a single project) and if you want to break out of that structure, the cost is time spent writing manual scripts to copy definitions around (and figuring out how to even get those definitions if using external modules), and then waiting for those scripts to run before having to run a full compile.
Visual Studio has a great solution for this when using .NET : interproject references. They're easy to set up and work great. If I have a .NET project with a client EXE, a server EXE, and a shared logic DLL, when I change the DLL, both the client and the server EXE projects know immediately and will show type errors via the language services - even before I've actually compiled the modified DLL. I'm yearning for such an experience in TypeScript.
I think that there may be a solution (pun intended) to this in TypeScript and it lies in allowing interproject references to be specified in the tsconfig.json file. Here is my idea:
"projectReferences": { "MyOtherProject1": ["../MyOtherProject1/tsconfig.json","external/MyOtherProject1.d.ts"], "MyOtherProject2": ["../MyOtherProject2/tsconfig.json","external/MyOtherProject2.d.ts"] }
The proposed projectReferences tag in tsconfig.json would be an object with named properties that are string arrays. Each property's value would be a series of fallback pointers to a file on disk relative to the tsconfig.json. The first element in each array that is found would be added to the compilation context for the current project only; the rest are ignored. If none are found, it is a compile error such as "Failed to resolve project reference for 'MyOtherProject1'.".
With this example tsconfig.json:
- If I have MyOtherProject1 cloned to my computer, then the files referenced by that project's tsconfig.json are added to my current project's compilation context.
- If I don't have MyOtherProject2 cloned to my computer, then the d.ts file that I've provided would be added to the compilation context instead. If that d.ts file is not found, it is a compiler error.
For me, this functionality (or something like it) would significantly improve the TypeScript modularization story and decrease the amount of plumbing I have to write to get different dependent modules in different folder structures compiling together.