As I try to transition a small JavaScript codebase to TypeScript, I'm encountering difficulties in writing type annotations for every function. One particular function that is causing me trouble involves returning from an await fetch
call.
Despite trying various options, Visual Studio keeps throwing errors at me. For instance, if I run a simple command like await fetch('google.com');
in Firefox console, it returns a Response
object. However, when I attempt to use Response or Promise in the function type annotations, I receive an error stating: "[Type] is not a valid async function return type because it does not refer to a Promise-compatible constructor value." It's becoming quite frustrating.
Below is the problematic function:
const updateLinkCount = async (id: string) /* : What type? */ => await fetch(uri, {
method: 'POST',
body: JSON.stringify({ id: id }),
headers: { 'Content-Type': 'application/json' }
});