Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Promises not working on IE11

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.

like image 735
Goca Avatar asked Feb 06 '16 02:02

Goca


People also ask

Do promises work in IE11?

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.

Is promise supported in Internet Explorer?

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.

Are promises supported in all browsers?

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.

What is polyfill promise?

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.


1 Answers

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.

like image 116
SnareChops Avatar answered Oct 07 '22 08:10

SnareChops