dispatchEvent Causes error failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type...
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
add a comment |
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
add a comment |
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
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
javascript angular typescript
asked Jan 29 '17 at 11:15
roni litmanroni litman
156114
156114
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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);
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 dispatchingeventwhich hasn't been defined. The correct variable should have beenev
– Data Crusader
Nov 14 '18 at 21:27
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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);
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 dispatchingeventwhich hasn't been defined. The correct variable should have beenev
– Data Crusader
Nov 14 '18 at 21:27
add a comment |
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);
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 dispatchingeventwhich hasn't been defined. The correct variable should have beenev
– Data Crusader
Nov 14 '18 at 21:27
add a comment |
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);
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);
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 dispatchingeventwhich hasn't been defined. The correct variable should have beenev
– Data Crusader
Nov 14 '18 at 21:27
add a comment |
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 dispatchingeventwhich hasn't been defined. The correct variable should have beenev
– 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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