javascript - 将 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"]
}
当我编译文件时,声明文件和 JavaScript 文件会在lib
文件夹中创建,这要归功于declaration
flag。但是,我的自定义界面没有被复制到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
我可以删除.d
扩展名,但随后,文件将作为 JavaScript 空模块生成。
当我使用 TypeScript 编译时,可以将这些文件直接放在lib
文件夹中,或者我应该使用一些命令复制这些文件:excp src/*.d.ts lib/
我不想使用复制方法,因为所有接口都会被导出,我只想导出模块中导出/使用的接口index.d.ts
。也许没有其他选择。
解决方案
推荐阅读
- javascript - 每 x 分钟/小时重置计时器
- maven - 覆盖默认的 maven 依赖解析行为
- javascript - 同时从 2 个选择框中删除相同的选项
- sql - Activerecord 将具有相同列值的行合并为一个
- vba - 基于另一个工作表的自动填充动态范围
- excel - 以编程方式添加没有 VBE 或 VBIDE 的 VBA 项目引用..?
- indexing - Terraform列表元素超出范围?
- javascript - Vue:传递给 vm.$nextTick 的函数何时执行?
- java - Java字节数组压缩
- python - 如何在字符之前获取所有内容并在之后获取 x 数量?