04-22-2018 18:47
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

04-22-2018 18:47
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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.
Answered! Go to the Best Answer.

Accepted Solutions
04-22-2018 19:37
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-22-2018 19:37
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
https://community.fitbit.com/t5/SDK-Development/Use-Promise-with-TypeScript/m-p/2231970
Gondwana Software

04-22-2018 19:37
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-22-2018 19:37
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
https://community.fitbit.com/t5/SDK-Development/Use-Promise-with-TypeScript/m-p/2231970
Gondwana Software

04-22-2018 20:00
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

04-22-2018 20:00
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
OK, I'll put in a dummy declaration.
BTW, even in JS "async" works which is far easier to read than promises.

04-22-2018 20:07
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-22-2018 20:07
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Yeah; I'm not a fan of the fetch/promise syntax. It seems to obscure the asynchronicity.
Gondwana Software

04-22-2018 20:14 - edited 04-22-2018 20:24
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

04-22-2018 20:14 - edited 04-22-2018 20:24
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
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);
// });});
04-22-2018 20:25
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-22-2018 20:25
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
You're right: I do prefer that! I've got some fetch() code with so many levels of indentation that it looks like LISP.
Gondwana Software

