typescript - 将私有(private)包安装到 @types - TypeScript 和 NPM

标签 typescript npm

我有一个只包含一个 index.d.ts 文件(TypeScript 定义文件)的存储库,我想在我拥有的多个存储库中共享它。类型定义文件中唯一的声明是一个接口(interface),如下所示:

interface MyInterface {
    thisSuperCoolFunction(): void;
}

不幸的是,定义存储库和我正在使用的所有其他存储库都是私有(private)的。是否可以将私有(private) npm typings 项目提交给 @types,这样安装它就可以正常工作,但不会将其暴露给其他任何人?

注意:不是 typings repo ,只有 @types 在 npm 上。

最佳答案

您不必将输入的内容发送到任何地方。您可以使用 git url as dependencylocal path


假设您要创建 @types/secret-library .你的类型在文件 index.d.ts 中.

创建 package.json@types/secret-library作为包名

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

git 网址

同时推送 index.d.tspackage.json一些 repo 例如git.acme.com/secret-project.git .

现在在您的其他项目中,您可以将此存储库作为依赖项引用

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

本地路径

如果两者都是index.d.tspackage.json在目录 /home/evil-genius/doom-saucer

您可以将此路径作为依赖引用

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

关于typescript - 将私有(private)包安装到 @types - TypeScript 和 NPM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41269664/

相关文章:

npm - 在 npm 中使用引导图标

typescript - 模拟器的 Firebase 功能,部署时忽略

javascript - 带有 wowJS 的 ReactJS 不工作

angular - 何时使用 RxJS Observable<Object[]> 和 Observable<Object>?

typescript - Angular 2 和模板 : Unterminated string literal. 在第 6 列 24

node.js - travis 成功运行后,语义发布不会发布

node.js - Package.json 与 GIT 工作流程 - 开发和主分支的独立依赖关系

javascript - Monaco Editor : Cannot find module 'monaco-editor' but it's installed

typescript - 如何从模块化 scss 导出推断类型?

function - 定义 TypeScript 变量类型函数或字符串