I was just playing with typescript and it's transpiling. Most of the stuff gets up and running but for the fetch I was just not able to make it to get transpiled. And I read a lot about it saying that I need the promise module/type. tried a couple of similar questions here but no success.
here is my tsconfing.json:
{
"compilerOptions": {
"target": "es5",
"lib": ["dom","es2017"]
}
}
what could have I missed?
thanks guys.
I figured it out.
By installing whatwg-fetch and promise, importing them to the ts file, transpiling it, and then packing it with webpack. If anybody can help further on how to achieve similar result with only typescript i would be very glad.
Thank you.
EDIT: To make things easier you can just use typescript and the two polyfill (any fetch/promise polyfill will do) modules. After that you import in the ts file:
import 'whatwg-fetch'
import 'Promise'
Transpile your ts file then you can either use webpack to glue all together or you can just use the cdn in your html file as I did.
https://cdn.jsdelivr.net/npm/whatwg-fetch@3.0.0/dist/fetch.umd.min.js https://cdn.jsdelivr.net/npm/promise@8.0.3/index.min.js
That is all folks.
tsconfig.js:
{
"compilerOptions": {
"target": "es5",
"lib": ["dom","es2017"]
}
}
npm dependencies used:
"devDependencies": {
"promise": "^8.0.3",
"whatwg-fetch": "^3.0.0"
}