简体   繁体   中英

Installing a private package to @types - TypeScript & NPM

I have a repo that's comprised only of an index.d.ts file (TypeScript definition file) that I want to share among a number of repos I have. The only declaration in the type definition file is an interface like so:

interface MyInterface {
    thisSuperCoolFunction(): void;
}

Unfortunately, the definition repo and all other repos I'm using are private. Is it possible to submit a private npm typings project to @types so that installing it will just work but also not expose it to anyone else?

Note: Not the typings repo, only @types on npm.

You don't have to send your typings anywhere. You can use git url as dependency or local path


Assuming you want to create @types/secret-library . And your types are in file index.d.ts .

Create package.json with @types/secret-library as a package name

// package.json
{
  "name": "@types/secret-library",
  "private": true,
  "types:" "index.d.ts"
}

git url

Push both index.d.ts and package.json to some repo eg git.acme.com/secret-project.git .

Now in your other project you can reference this repository as a dependency

// package.json
{
  "name": "doom-machine",
  "private": true,
  "dependencies":{
      "@types/secret-library": "git://git.acme.com/secret-project.git"
  }
}

local path

If both index.d.ts and package.json are in directory /home/evil-genius/doom-saucer

You can reference this path as a dependency

// package.json
{
  "name": "doom-machine",
  "private": true,
  "dependencies":{
      "@types/secret-library": "file:/home/evil-genius/doom-saucer"
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM