Using SVG.select() method with class selector of the svg.js library doesn't work with typescript

北战南征 提交于 2019-12-24 21:13:55

问题


I'm testing svg.js library with typescript and having some problems with usage of CSS selectors. I would like to select SVG element using select() method with class selector. In the presented fiddle it works perfectly with javascript:

var circleTwo = SVG.select('circle.circle-01');

Unfortunately, it doesn't work with typescript. Lib is imported like that:

import * as SVG from 'svg.js;

When hover on select() method, getting the info about second parameter:

However according to the documentation

Additionally, a second argument can be passed to define the parent element to search in

It seems that it is an optional argument because you can use select() method without it:

var elements = SVG.select('rect.my-class').fill('#f06')

I've played a bit and found how to get rid of this error (the question is, is this correct approach?), however I can't use later the click() event on the selected element, because of another error:

Property 'click' does not exist on type 'Set'.

testMe() is the simple method to test the click() event on the selected element:

  testMe() {
    alert('it works even better!');
  }

What am I doing wrong?


回答1:


Seems like the type definitions are wrong. Thats not your fault, you should open a bug report. Until it gets fixed you could work around it:

SVG.select('rect.my-class', undefined as any)


来源:https://stackoverflow.com/questions/49387057/using-svg-select-method-with-class-selector-of-the-svg-js-library-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!