I'm making a project in TypeScript (Mainly to learn more about TypeScript) that uses the wikipedia npm package and this error came up and I can't figure out what's the problem. The issue is that I have an async function and it returns a json (A wikipedia summary). The problem is that when I assign it to a variable, it shows an error at res
:
Type 'Promise<wikiSummary>' is missing the following properties from type 'wikiSummary': type, title, displaytitle, namespace, and 15 more.
Code:
async function getSummary(searchword: string) {
try {
const response: wikiSummary = await wiki.summary(searchword);
return response;
} catch (error) {
console.log(error);
}
}
const res: wikiSummary = getSummary(search); // error here
I have looked it up to see if someone had the same problem and it wasn't really what I looked for. I also can just remove the type annotation but I want to know why this is happening for my own knowledge.