Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Where is the definition of fetch

ANSWERED

If I try to use fetch in a .typescript application I'm told it is not defined the documentation doesn't tell me where to find the definition.

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions
Best Answer
0 Votes
5 REPLIES 5
Best Answer
0 Votes

OK, I'll put in a dummy declaration.

 

BTW, even in JS "async" works which is far easier to read than promises.

Best Answer
0 Votes

Yeah; I'm not a fan of the fetch/promise syntax. It seems to obscure the asynchronicity.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Then you might enjoy the comparison. I commented out the promise syntax. This works in JS/TS now

 

(Too bad paste loses the indentation -- I tried to recover it but sloppy.).


console.log("Did await");
const resp = await fetch("http://Frankston.com");
const tx1 = await resp.text()
const txt = tx1.substr(0, 20);
const data = new Uint8Array(txt.length);
for (let ctr = 0; ctr < data.length; ctr++) {
   data[ctr] = txt.charCodeAt(ctr);
}
outbox.enqueue("alphabits.txt", data);
console.log("Did await");

 

//fetch("http://Frankston.com").then(resp => {
//   resp.text().then(txt => {
//         console.log(`Got txt ${txt.substr(0,10)}`);
//         txt = txt.split('\n')[1];
//         let data = new Uint8Array(txt.length);
//         for (let counter = 0; counter < data.length; counter++) {
//              data[counter] = txt.charCodeAt(counter);
//         }
//         outbox.enqueue("alphabits.txt", data);
// });});

Best Answer

You're right: I do prefer that! I've got some fetch() code with so many levels of indentation that it looks like LISP.

Peter McLennan
Gondwana Software
Best Answer
0 Votes