I am trying to understand why the return type string in the following method is underlined red as error:
exportPageAsText(pageNumber: number): string {
(async () => {
const text = await this.pdfViewerService.getPageAsText(pageNumber);
console.log(text);
return text;
})();
}
The error message reads: A function whose declared type is neither 'void' nor 'any' must return a value. so I moved return text; out of the async scope and placed it after })(); but that made the text variable unrecognizable.
Then I thought maybe it's because the method return type should be a Promise so I changed the signature to:
exportPageAsText(pageNumber: number): Promise<string>
But I get a new error saying that A function whose declared type is neither 'void' nor 'any' must return a value.
Can someone please help me understand what I am doing wrong?
(async () => {, you're creating a new function, so this is that function that should have a return type