I'm trying to modify a type declaration for a package that I'm using since the types are outdated. I'm able to adjust most things fine, but there is one error I don't seem to be able to fix, and that is that a property of an interface that is returned from the function.
Here is a code sample. I have stripped out code I am pretty sure are not related to the issue, to make reading it easier. If you feel there is something missing that might help understand the problem, please let me know.
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;
When I then use this in my code like so:
const { image } = await renderContent(file, options);
I get an error saying:
Property 'image' does not exist on type 'false | HTMLImageElement | FileReader | PromiseData'
To me, it seems it is clearly defined in the PromiseData interface, listed in the error message. So what am I missing?