【发布时间】:2020-06-09 14:13:06
【问题描述】:
我正在尝试修改我正在使用的包的类型声明,因为这些类型已过时。我可以很好地调整大多数东西,但有一个错误我似乎无法修复,那就是从函数返回的接口属性。
这是一个代码示例。我已经删除了我很确定与问题无关的代码,以使其更容易阅读。如果您觉得缺少一些可能有助于理解问题的内容,请告诉我。
declare namespace renderContent {
type renderContentCallback = (
eventOrImage: Event | HTMLCanvasElement | HTMLImageElement,
data?: MetaData
) => void;
interface ImageHead {
imageHead?: ArrayBuffer | Uint8Array;
}
interface MetaData extends ImageHead {
//...
}
interface PromiseData extends MetaData {
image: HTMLCanvasElement | HTMLImageElement;
}
interface BasicOptions {
//...
}
type renderContentOptions = BasicOptions
}
interface renderContent {
(
file: File | Blob | string,
/* If options are defined instead of a callback function, the next argument will be skipped and the function will return a promise */
callbackOrOption?: renderContent.renderContentCallback | renderContent.renderContentOptions,
options?: renderContent.renderContentOptions
): HTMLImageElement | FileReader | Promise<renderContent.PromiseData> | false;
}
declare const renderContent: renderContent;
export = renderContent;
当我像这样在我的代码中使用它时:
const { image } = await renderContent(file, options);
我收到一条错误消息:
类型“假”上不存在属性“图像”| HTMLImageElement | 文件阅读器 | PromiseData'
对我来说,它似乎在 PromiseData 接口中明确定义,并在错误消息中列出。那我错过了什么?
【问题讨论】:
标签: typescript