I'm new to Promises on javascript so I hope some can help me with this issue.
Problem: Promise not being execute on IE11, works fine on Chrome and FireFox
Frameworks used: I tried using es6-promise.d.ts and bluebird.d.ts same result.
Code:
static executeSomething(): Promise<any>
{
console.log("inside executeSomething");
var test= new Promise((resolve, reject)=>
{
console.log("inside Promise");
}).catch(function(error){console.log("error")});
console.log("after promise");
return test;
}
Results: on chrome and Firefox I can see all the logs but on IE11 I only see "Inside executeSomething" which means the problem is while creating the promise.
I thought it was because IE11 didn't support es6 but I get the same result using bluebird, I hope some can bring some light to my issue.
The Built-In Promise Object ES2015 includes the built-in `Promise` function-object. IE11 does not support this object, so you should use a polyfill like es6-promise.
Enabling Internet Explorer SupportRecent versions of other browsers – including Edge (Internet Explorer's successor), Chrome, Safari, Firefox and Opera – all have native Symbol, Promise, and Fetch support.
Promises work in the latest versions of all modern browsers; the only place where promise support will be a problem is in Opera Mini and IE11 and earlier versions.
Promise Usage. The promise is a constructor which accepts an executor function as a parameter. The executor function has a resolve callback, and a reject callback as its parameter. Once the Promise constructor is called, an async operation is initiated, say, an HTTP API call.
You need to include a promise polyfill in your page for IE11 to work.
Your instinct to use es-promise is correct, but you need to also include the .js
file in your html
<script src="path/to/es6-promise.js"></script>
The .d.ts
file will give the TypeScript compiler it's definitions, but does not affect runtime. You still need to include the polyfill in your html for it to actually run in the browser.
The biggest thing to remember when using TypeScript or any compiled language is the difference between compile time and run time.
.d.ts
, .ts
, .tsx
, etc. Are all compile time files. Which means that these are not the files that are actually executed, but instead the files that generate the runtime code.
.js
files are the runtime files. These are the files that are run by the browser.
.d.ts
files do not contain code, but instead a definition of the code's signature and therefore should always be accompanied with a corresponding .js
file that will run in the browser.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With