我的 UI 包没有类型定义文件。当我在 TypeScript 项目中使用它时
import { Cell } from 'zarm';
TSC 将抛出错误:
Could not find a declaration file for module 'zarm'.
我创建了一个 global.d.ts
文件,并尝试声明 zarm
模块来导出任何内容。
declare module 'zarm' {
const x: any;
export = x;
}
TSC 抛出:
Module '"zarm"' has no exported member 'Cell'.
zarm模块中有很多组件,我只想声明zarm模块来导出any
。不要关心它到底导出什么。
最佳答案
您可以使用Shorthand ambient modules .
If you don’t want to take the time to write out declarations before using a new module, you can use a shorthand declaration to get started quickly.
只需在 global.d.ts
类型定义文件中为现有 JavaScript 包 zarm
声明模块即可:
declare module 'zarm';
它可以让您导入 any
类型的 zarm
模块。这样我就可以从模块导入任何组件,而无需使用 //@ts-ignore
注释来跳过 TSC 类型检查。
import { Button, Popup } from 'zarm';
关于typescript - 如何声明一个模块导出任何内容,无论它导出什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68740452/