Re:Better Promises in JavaScript
by zebracanevra on Monday September 24, 2018 @10:48AM
(#18058139)
fetch's Response.text also returns a Promise, so you'd have to await twice:
[ Parent
| on HN ]
I've always just added an overload:
function fetchText(input?: string | Request, init?: RequestInit) {
return fetch(input, init).then(x => x.text())
}
function fetchJson(input?: string | Request, init?: RequestInit) {
return fetch(input, init).then(x => x.json())
}