javascript - 从 typescript 定义 d.ts 文件动态加载接口
问题描述
我有一个.d.ts
包含接口的文件。我不知道预先存在哪些接口。这些.d.ts
文件是由第三方库生成的,而不是从相应的文件中生成的.ts
。
export interface ExampleInterface1 {
id: string;
type: string;
}
export interface ExampleInterface2 {
id: string;
type: string;
}
因此,我想动态加载`.d.ts
const data = await import('path/to/my/dynamically/created/file'); // without .d.ts extension
但是,这不适用于.d.ts
文件。我用其他文件进行了测试,包括 JSON,并且内容被很好地加载到data
变量中。
我可以手动导入,但当然,这对我的情况没有帮助。
import { ExampleInterface1, ExampleInterface2 } from 'path/to/my/dynamically/created/file';
如何从.d.ts
文件中动态加载接口名称和内容?
解决方案
推荐阅读
- c# - 将第一个字符与单词的每个其他字符组合在一起
- php - php-fpm 和 nginx 图像和 css 在多容器设置中提供服务
- google-cloud-platform - 如何每 5 分钟运行一次 Cloud Scheduler 作业
- javascript - 如何删除由谷歌翻译按钮在网页顶部和页脚创建的空白?
- c - 仅当我打印了属性的值时,功能才能正常工作
- jquery - 为什么调用 location.reload(); 后我的表中的行顺序会发生变化?关闭模态框时
- django - Vue中使用axios请求后端接口出错
- c++ - LLVM:没有识别的结构
- light-4j - 我们如何在 logback.xml 中为 light-4j 应用程序集成访问日志?
- python - 如何在python中从右到左使用非贪婪的正则表达式?