As far as I know, there isn't a simple one-step solution because npm and yarn currently do not support direct installation from a subdirectory of a git repository. You can check the known issues on npm and yarn, as well as past discussions on Stack Overflow like this one. If your git repository provides a URL to download a tarball of a specific subdirectory, you could attempt running npm install
using that URL, although I have not tried this method myself.
One suggestion is to utilize Braid (full disclosure: I contribute to Braid) to duplicate the needed subdirectory from the DefinitelyTyped fork into your project's directory and then execute npm install
or yarn add
on that copied content. This way, either npm or yarn will create a symbolic link from the appropriate location within node_modules
to the subdirectory, allowing TypeScript to access the type declarations seamlessly. Since the DefinitelyTyped repository may lack complete package.json
files for individual types packages, you might have to manually create or update the necessary fields in the local subdirectory's package.json
before proceeding with npm install
. You can consider leaving these modifications as downstream changes to the Braid mirror.
The main downside of this workaround is that it duplicates the types package in the downstream repository, occupying additional space permanently. Additionally, Braid will replicate the entire history of DefinitelyTyped into your local clone of the downstream repository, but this overhead can be managed through garbage collection to reclaim space.