thiagobustamante / typescript-ioc

A Lightweight annotation-based dependency injection container for typescript.
MIT License
526 stars 64 forks source link

Container.bind doesn't work in IE #12

Closed drwatson1 closed 6 years ago

drwatson1 commented 7 years ago

... but works fine in Edge and Chrome.

I've created a repo to reproduce the problem here: https://github.com/drwatson1/typescript-ioc-example

If you'll try to open the example in IE you'll see these errors:

InjectorHanlder.getConstructorFromType
D:\GitHub\typescript-ioc-example\node_modules\typescript-ioc\es5.js:288
  285 |                 return typeConstructor;
  286 |             }
  287 |         }
> 288 |         throw TypeError('Can not identify the base Type for requested target');
  289 |     };
  290 |     return InjectorHanlder;
  291 | }());

IoCContainer.isBound
D:\GitHub\typescript-ioc-example\node_modules\typescript-ioc\es5.js:91
  88 | }
  89 | IoCContainer.isBound = function (source) {
  90 |     checkType(source);
> 91 |     var baseSource = InjectorHanlder.getConstructorFromType(source);
  92 |     var config = IoCContainer.bindings.get(baseSource);
  93 |     return (!!config);
  94 | };

Container.bind
D:\GitHub\typescript-ioc-example\node_modules\typescript-ioc\es5.js:74
  71 | function Container() {
  72 | }
  73 | Container.bind = function (source) {
> 74 |     if (!IoCContainer.isBound(source)) {
  75 |         AutoWired(source);
  76 |         return IoCContainer.bind(source).to(source);
  77 |     }

Anonymous function
D:\GitHub\typescript-ioc-example\src\ioc.ts:14
  11 | /// 
  12 | const Container = require('typescript-ioc/es5.js').Container;
  13 | 
> 14 | Container.bind(SomeService).to(SomeServiceImpl);
  15 | 
  16 | export {
  17 |     SomeService,

... and so on.

thiagobustamante commented 7 years ago

Hi, I am compiling the source using ES5 and ES6 as output for typescript compiler. Depending on the IE version, it does not support ES5 yet. Which version of IE are you using?

I did not try to compile it to ES3 and don't know if there is a problem to generate an ES3 version, but we can try it

drwatson1 commented 7 years ago

I'm using IE 11. But as outlined here IE support ES5 from version 9.

IE9 has 83% functionality of ES5, IE10-11 - 99%.

I think It would be great to determine the exact reason of this behavior. May be there is another solution that can work in IE.

cfmano commented 6 years ago

We have the same problem and were able to fix it locally. Can I create Pull request for this?

thiagobustamante commented 6 years ago

@cfmano Yes. A PR is very welcome!