我有几个.ts文件+ 1入口点,像这样:
- classA.ts
- classB.ts
- entrypoint.ts
entrypoint.ts
包含类似于:
export * from './classA';
export * from './classB';
我想要一间单人房。
ClassA
和ClassB
定义文件。不能自动生成单个d.ts
文件。下面的代码可以正常工作(假设您正在构建一个库/可重用模块):
让编译器通过在
tsconfig.json
中指定编译器也会生成一个
entrypoint.d.ts
文件(重新导出类a和类b的d.ts
)将
package.json
的typings
条目指向entrypoint.d.ts
,例如"typings": "./dist/entrypoint.d.ts"
"declaration": true
来自动生成类声明假设您的库名为library
,您现在可以将其安装在项目的node_modules
中,并与标准导入一起使用:
import {classA, classB} from 'library'
将为这些类导入生成的d.ts.
。
任何发现这篇文章的人。您可以尝试npm-dts实用程序。
这个很适合我,它很直接:https://github.com/TypeStrong/dts-bundle
我试了这些没有运气:
- https://github.com/Microsoft/dts-gen
- https://github.com/SitePen/dts-generator