导出单.d.从几个typescript文件+入口点



我有几个.ts文件+ 1入口点,像这样:

  • classA.ts
  • classB.ts
  • entrypoint.ts

entrypoint.ts包含类似于:

export * from './classA';
export * from './classB';
我想要一间单人房。
描述入口点导出的所有内容,以便包含ClassAClassB定义文件。

不能自动生成单个d.ts文件。下面的代码可以正常工作(假设您正在构建一个库/可重用模块):

  1. 让编译器通过在tsconfig.json

  2. 中指定"declaration": true来自动生成类声明
  3. 编译器也会生成一个entrypoint.d.ts文件(重新导出类a和类b的d.ts)

  4. package.jsontypings条目指向entrypoint.d.ts,例如"typings": "./dist/entrypoint.d.ts"

假设您的库名为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

最新更新