AFAIK, there's no one-step solution because npm and yarn don't support installing directly from a subdirectory of a git repository. See the issues for npm (maybe there is a newer one) and yarn and previous Stack Overflow questions including this one. (If your repository is hosted on a service that offers a URL to download a tarball of a subdirectory of the repository, you could try running npm install
on that URL; I didn't pursue that approach.)
I suggest you use Braid (disclosure: I am a Braid contributor) to copy the subdirectory of the DefinitelyTyped fork into a subdirectory of your project and then run npm install
(or yarn add
) on that subdirectory. npm
or yarn
will create a symlink from the appropriate location under node_modules
to the subdirectory, so TypeScript will find the type declarations without additional configuration. Since the DefinitelyTyped repository does not contain fully functional package.json
files for individual types packages, you'll likely need to create the package.json
file in the local subdirectory or add the missing fields to it before running npm install
. (You can just leave this change as a downstream change to the Braid mirror.)
The only drawback I see in this solution is that it makes a copy of the types package in the downstream repository, which will permanently take up some space in the repository. (And Braid will copy the entire history of DefinitelyTyped into your local clone of the downstream repository, but that space can be reclaimed by garbage collection.)
index.d.ts
insrc>custom_typings>[package_name]
folder. You would need to add:"typeRoots": ["./node_modules/@types", "./src/custom-typings"],
and"paths":{"[package_name]": ["./src/custom-typings/[package_name]"], "[package_name]/*": ["./src/custom-typings/[package_name]/*"]}
– Destruction