我有一个回购协议,该回购协议仅涉及index.d.ts我要在多个存储库中共享的文件(TypeScript定义文件)。类型定义文件中的唯一声明是如下所示的接口:
interface MyInterface {
thisSuperCoolFunction(): void;
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,定义库和我正在使用的所有其他库都是私有的。是否可以向其提交私有的npm类型项目,@types以便安装它既可以工作,又不会向其他任何人公开?
注意:仅在npm上没有键入回购@types。
您无需将输入内容发送到任何地方。您可以使用git url作为依赖项或本地路径
假设您要创建@types/secret-library。并且您的类型在文件中index.d.ts。
创建package.json与@types/secret-library作为包名
// package.json
{
"name": "@types/secret-library",
"private": true,
"types:" "index.d.ts"
}
Run Code Online (Sandbox Code Playgroud)
既推index.d.ts及package.json到一些回购如git.acme.com/secret-project.git。
现在,在您的其他项目中,您可以将此存储库引用为依赖项
// package.json
{
"name": "doom-machine",
"private": true,
"dependencies":{
"@types/secret-library": "git://git.acme.com/secret-project.git"
}
}
Run Code Online (Sandbox Code Playgroud)
如果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"
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1500 次 |
| 最近记录: |