Joh*_*son 9 npm type-declaration typescript
鉴于以下文件夹结构:
src/
??? foo.ts
??? bar.ts
??? baz.ts
??? index.ts
Run Code Online (Sandbox Code Playgroud)
其中foo.ts、bar.ts和baz.ts每个都导出一个默认类或事物:即在以下情况下foo.ts:
export default class Foo {
x = 2;
}
Run Code Online (Sandbox Code Playgroud)
我们可以自动生成该声明的声明文件,一个模块 my-module和出口foo.ts,bar.ts以及baz.ts作为非默认?
即我想tsc生成以下内容:
build/
??? foo.js
??? bar.js
??? baz.js
??? index.js
??? index.d.ts
Run Code Online (Sandbox Code Playgroud)
其中index.d.ts包含:
declare module 'my-module' {
export class Foo {
...
}
export class Bar {
...
}
export class Baz {
...
}
}
Run Code Online (Sandbox Code Playgroud)
我看到大多数 NPM 模块都有一个这样的声明文件,可能还有单独的文件。
我将如何做到这一点?
小智 0
在 tsconfig.json 文件中,将“声明”设置为 true。然后,当您在项目上运行 typescript 时,它会自动为您生成声明文件。
| 归档时间: |
|
| 查看次数: |
2085 次 |
| 最近记录: |