相关疑难解决方法(0)

在 Typescript 中导出和发布所有类型和接口

我正在尝试发布一个打字稿库。我不清楚如何公开所有类型和接口。这是我的设置:

mylib
  ???src
  ?  ???types
  |  |  ???mytypes.ts
  ?  ???index.ts
  ???package.json
  ???tsconfig.json
Run Code Online (Sandbox Code Playgroud)
mylib
  ???src
  ?  ???types
  |  |  ???mytypes.ts
  ?  ???index.ts
  ???package.json
  ???tsconfig.json
Run Code Online (Sandbox Code Playgroud)
//index.ts

import {MyInterface} from './types/mytypes.ts';

const my_main_name = {
  myfunc: function(param1:MyInterface):void{
    console.log(param1.a);
  }
}

Run Code Online (Sandbox Code Playgroud)

我通过设置tsconfig.jsonparam生成声明文件"declaration":"true"。

现在我想使用这个库作为另一个库的依赖。

mylib
yrlib
  ???src
  ?  ???index.ts
  ???package.json
  ???tsconfig.json
Run Code Online (Sandbox Code Playgroud)
//mytypes.ts

export interface MyInterface {
  a:string
}

Run Code Online (Sandbox Code Playgroud)
mylib
yrlib
  ???src
  ?  ???index.ts
  ???package.json
  ???tsconfig.json
Run Code Online (Sandbox Code Playgroud)

mylib因为它是导出的,所以我得到了自动完成。

我的问题是如何查看mylib模块内部的所有类型和接口yrlib?

因为它们可以是数百个并且位于所有不同的文件和文件夹中。

我应该一一导出所有这些吗?最佳做法是什么?有没有办法一次导出所有类型?

而如何"typying":"dist/index.d.ts"在package.json这一切发作?应该是一个文件中的所有类型吗?为什么 Typescript 不生成这个文件? …

typescript

4
推荐指数
1
解决办法
2305
查看次数

标签 统计

typescript ×1