dispatchEvent Causes error failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type...












4















I am using Angular2 + TypeScript and when I try execute this code:



var event = new Event('check');
window.dispatchEvent(event);


This code causing the next error:




failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type 'Event'.




I have tried everything, and found out that this will work:



var event = new CustomEvent('check');


Problem is that CustomEvent is not supported by any IE.



Another thing that works is:



var event = new Event('CustomEvent');
event.initCustomEvent('check');


Problem is that InitCustomEvent is deprecated.



Is there anything I can do to avoid this type error? Maybe make an exception somewhere in typescript? Or use any code that is not deprecated and works for IE Edge?










share|improve this question



























    4















    I am using Angular2 + TypeScript and when I try execute this code:



    var event = new Event('check');
    window.dispatchEvent(event);


    This code causing the next error:




    failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type 'Event'.




    I have tried everything, and found out that this will work:



    var event = new CustomEvent('check');


    Problem is that CustomEvent is not supported by any IE.



    Another thing that works is:



    var event = new Event('CustomEvent');
    event.initCustomEvent('check');


    Problem is that InitCustomEvent is deprecated.



    Is there anything I can do to avoid this type error? Maybe make an exception somewhere in typescript? Or use any code that is not deprecated and works for IE Edge?










    share|improve this question

























      4












      4








      4








      I am using Angular2 + TypeScript and when I try execute this code:



      var event = new Event('check');
      window.dispatchEvent(event);


      This code causing the next error:




      failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type 'Event'.




      I have tried everything, and found out that this will work:



      var event = new CustomEvent('check');


      Problem is that CustomEvent is not supported by any IE.



      Another thing that works is:



      var event = new Event('CustomEvent');
      event.initCustomEvent('check');


      Problem is that InitCustomEvent is deprecated.



      Is there anything I can do to avoid this type error? Maybe make an exception somewhere in typescript? Or use any code that is not deprecated and works for IE Edge?










      share|improve this question














      I am using Angular2 + TypeScript and when I try execute this code:



      var event = new Event('check');
      window.dispatchEvent(event);


      This code causing the next error:




      failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type 'Event'.




      I have tried everything, and found out that this will work:



      var event = new CustomEvent('check');


      Problem is that CustomEvent is not supported by any IE.



      Another thing that works is:



      var event = new Event('CustomEvent');
      event.initCustomEvent('check');


      Problem is that InitCustomEvent is deprecated.



      Is there anything I can do to avoid this type error? Maybe make an exception somewhere in typescript? Or use any code that is not deprecated and works for IE Edge?







      javascript angular typescript






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 29 '17 at 11:15









      roni litmanroni litman

      156114




      156114
























          1 Answer
          1






          active

          oldest

          votes


















          3














          Found a solution.



          For some TypeScript settings, new Event is type of 'Event' only when we insert the second parameter, as this example:



          var event = new Event("check", { bubbles: true, cancelable: false });
          window.dispatchEvent(event);





          share|improve this answer





















          • 5





            pasting this into the chrome console I get the same error.

            – Jacksonkr
            Jun 30 '17 at 21:35











          • @Jacksonkr that is caused by the fact that we're dispatching event which hasn't been defined. The correct variable should have been ev

            – Data Crusader
            Nov 14 '18 at 21:27











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f41920266%2fdispatchevent-causes-error-failed-to-execute-dispatchevent-on-eventtarget-p%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          Found a solution.



          For some TypeScript settings, new Event is type of 'Event' only when we insert the second parameter, as this example:



          var event = new Event("check", { bubbles: true, cancelable: false });
          window.dispatchEvent(event);





          share|improve this answer





















          • 5





            pasting this into the chrome console I get the same error.

            – Jacksonkr
            Jun 30 '17 at 21:35











          • @Jacksonkr that is caused by the fact that we're dispatching event which hasn't been defined. The correct variable should have been ev

            – Data Crusader
            Nov 14 '18 at 21:27
















          3














          Found a solution.



          For some TypeScript settings, new Event is type of 'Event' only when we insert the second parameter, as this example:



          var event = new Event("check", { bubbles: true, cancelable: false });
          window.dispatchEvent(event);





          share|improve this answer





















          • 5





            pasting this into the chrome console I get the same error.

            – Jacksonkr
            Jun 30 '17 at 21:35











          • @Jacksonkr that is caused by the fact that we're dispatching event which hasn't been defined. The correct variable should have been ev

            – Data Crusader
            Nov 14 '18 at 21:27














          3












          3








          3







          Found a solution.



          For some TypeScript settings, new Event is type of 'Event' only when we insert the second parameter, as this example:



          var event = new Event("check", { bubbles: true, cancelable: false });
          window.dispatchEvent(event);





          share|improve this answer















          Found a solution.



          For some TypeScript settings, new Event is type of 'Event' only when we insert the second parameter, as this example:



          var event = new Event("check", { bubbles: true, cancelable: false });
          window.dispatchEvent(event);






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 14 '18 at 21:54









          Data Crusader

          1441213




          1441213










          answered Feb 6 '17 at 9:36









          roni litmanroni litman

          156114




          156114








          • 5





            pasting this into the chrome console I get the same error.

            – Jacksonkr
            Jun 30 '17 at 21:35











          • @Jacksonkr that is caused by the fact that we're dispatching event which hasn't been defined. The correct variable should have been ev

            – Data Crusader
            Nov 14 '18 at 21:27














          • 5





            pasting this into the chrome console I get the same error.

            – Jacksonkr
            Jun 30 '17 at 21:35











          • @Jacksonkr that is caused by the fact that we're dispatching event which hasn't been defined. The correct variable should have been ev

            – Data Crusader
            Nov 14 '18 at 21:27








          5




          5





          pasting this into the chrome console I get the same error.

          – Jacksonkr
          Jun 30 '17 at 21:35





          pasting this into the chrome console I get the same error.

          – Jacksonkr
          Jun 30 '17 at 21:35













          @Jacksonkr that is caused by the fact that we're dispatching event which hasn't been defined. The correct variable should have been ev

          – Data Crusader
          Nov 14 '18 at 21:27





          @Jacksonkr that is caused by the fact that we're dispatching event which hasn't been defined. The correct variable should have been ev

          – Data Crusader
          Nov 14 '18 at 21:27




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f41920266%2fdispatchevent-causes-error-failed-to-execute-dispatchevent-on-eventtarget-p%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          List item for chat from Array inside array React Native

          Thiostrepton

          Caerphilly