You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
async function deleteUser(id:string) {
const url = `/v1/users/${id}`;
let reqObj = {
method: 'DELETE',
credentials: "same-origin"
}
try {
const result = await fetch(url, reqObj);
const body = await result.json();
if (!body || !body.success) {
return ;
}
return true;
} catch (err) {
console.log(err);
}
}
Raises the following error:
TS2345: Argument of type '{ method: string; credentials: string; }' is not assignable to parameter of type 'RequestInit'.
Types of property 'credentials' are incompatible.
Type 'string' is not assignable to type 'RequestCredentials'.
But if we pass RequestInit object directly without assigning to a variable, like this:
When you pass it inline, the object literal is contextually typed by the signature of the fetch function. When you declare it beforehand there is no such context and especially given that the object property is mutable, it's type is inferred as string.
TypeScript Version: 2.7.1
Raises the following error:
But if we pass RequestInit object directly without assigning to a variable, like this:
It doesn't raise any error
The text was updated successfully, but these errors were encountered: