Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call stopPropagation in Typescript

I'm trying to use stopPropagation method. I use d3.js with d3.d.ts (downloaded via typings). Is it possible to call stopPropagation somehow? I used event.stopPropagation() until I've run my application in firefox. Typings does have d3.event but it doesn't contain declaration of mentioned method.

like image 975
Julian Rubin Avatar asked Jun 19 '16 20:06

Julian Rubin


1 Answers

It wasn't that hard actually. For stopPropagation I needed:

(d3.event as Event).stopPropagation();

The typings says that:

event: Event | BaseEvent

So essentialy event can be any of those. I've forgotten how union works in typescript. As the type property is only one common among Event and BaseEvent it was displayed solely. The one case when I needed cast to BaseEvent (I believe it is only used by d3) was on the dragstart event.

like image 152
Julian Rubin Avatar answered Oct 11 '22 18:10

Julian Rubin