我有一个只包含一个 index.d.ts
文件(TypeScript 定义文件)的存储库,我想在我拥有的多个存储库中共享它。类型定义文件中唯一的声明是一个接口(interface),如下所示:
interface MyInterface {
thisSuperCoolFunction(): void;
}
不幸的是,定义存储库和我正在使用的所有其他存储库都是私有(private)的。是否可以将私有(private) npm typings 项目提交给 @types
,这样安装它就可以正常工作,但不会将其暴露给其他任何人?
注意:不是 typings repo ,只有 @types
在 npm 上。
最佳答案
您不必将输入的内容发送到任何地方。您可以使用 git url as dependency或 local 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.ts
和 package.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.ts
和 package.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/