Sna*_*rak 7 javascript node-modules typescript
我在 TypeScript 中有一个模块,当它被编译时,它不会复制我的自定义声明文件,例如接口。
配置示例:
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"declaration": true,
"outDir": "./lib",
"strict": true,
"typeRoots": ["node_modules/@types"],
"esModuleInterop": true
},
"include": ["src/**/*.ts"],
"exclude": ["dist", "lib", "node_modules"]
}
Run Code Online (Sandbox Code Playgroud)
当我编译文件时,声明文件和 JavaScript 文件会在lib文件夹中创建,这要归功于declarationflag。但是,我的自定义界面没有复制到lib,它们可能很有用。
结构示例:
/lib
- index.d.ts // It contains an error because it is trying to export interface, and it is not in the folder
- index.js
- example.js
- example.d.ts
- interface.d.ts // missing!!
/src
- index.ts // Here is exported my interface and example function
- example.ts
- interface.d.ts
Run Code Online (Sandbox Code Playgroud)
我可以删除.d扩展名,但是,这些文件将作为 JavaScript 空模块生成。
lib当我使用 TypeScript 编译时,可以直接将这些文件放在文件夹中,或者我应该使用一些命令复制这些文件:excp src/*.d.ts lib/
我不想使用 copy 方法,因为所有接口都会被导出,我只想导出模块中导出/使用的接口index.d.ts。也许没有其他选择。
| 归档时间: |
|
| 查看次数: |
233 次 |
| 最近记录: |