3 ms·
fetch's Response.text also returns a Promise, so you'd have to await twice: const lines = (await (await fetch(myUrl)).text()).split('\n');
by zebracanevra 8y ago
fetch's Response.text also returns a Promise, so you'd have to await twice:
const lines = (await (await fetch(myUrl)).text()).split('\n');
- mnr 8y agoShucks, I can see how it becomes verbose.
- mikewhy 8y agoI'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()) }