This is a demonstration of a composite TypeScript project configuration with pnpm workspaces.
The workspace consists of three projects: client, api, service. The basic idea is that a browser-based application (client) is communicating to api through service.
The challenge that this repo demonstrates a solution to is how to organize multiple projects in a monorepo, so that their dependency tree is reflected correctly, as well as taking advantage of incremental typescript compilation.
clientshould have access to browser-native types (such aswindow), but not have access to node types, such asprocessapiandserviceshouldn't have access to browser types, but should be able to access node typesapiis a dependency ofservice, and should be listed in its list of dependenciesapiis not a dependency ofclient, yet we want to be able to importAPItype to allow type-safe integration.
And we want to run type checking on all projects incrementally with one command, taking into account their respective environments
- Root
tsconfigdoes not include any files (runningtsc -p . --listFilesshould produce nothing) - However, root
tsconfigincludes references toserviceandclientprojects runningtsc --buildwill build all referenced projects incrementally (tsc --build --verbosewill show projects built) servicelists@cw/apiin its dependencies, which means that when we installservicedependencies,apiand its dependencies will be included in installservicetsconfigincludes a reference toapito include it in composite compilation treeclientdoesn't listapiin dependencies, but references it intsconfig