TL;DR使用以下命令生成模块的声明declaration: true
in tsconfig.json
并在中指定生成的类型的文件typings
的条目package.json
file
框架
Use a tsconfig
与此类似的文件:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": true,
"noImplicitAny": true,
"removeComments": true,
"outDir": "dist",
...
},
"files": [
...
]
}
重要的是declaration: true
这将在 dist 目录中生成内部声明
假设有一个index.ts
文件(重新)导出所有有趣的部分framework
, 创建一个package.json
文件带有main
and typings
Entry分别指向生成的js和生成的声明,即
{
"name": "framework",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
...
}
将此模块提交到 git 存储库,例如 bitbucket:“https://[电子邮件受保护]/myUser/framework.git https://myUser@bitbucket.org/myUser/framework.git"
dep-a
in package.json
创建依赖关系framework
{
"dependencies": {
"framework": "https://[email protected] /cdn-cgi/l/email-protection/myUser/framework.git"
},
}
这就对了。
import * from 'framework'
将拉取依赖with自动打字
显然,可以这样做dep-a做了什么框架即生成声明、更新 package.json 并使用dep-a作为嵌入类型的模块main
注意:如果您不想通过外部 git 存储库访问,则可以在 package.json/dependencies 中添加文件 URL