How to use SVGDocument in Typescript?

前端 未结 2 1491
深忆病人
深忆病人 2021-01-15 05:46

According to the W3C recommendations, the method getSVGDocument()should return an SVGDocument, but the code in lib.d.ts is:

interfa         


        
2条回答
  •  不要未来只要你来
    2021-01-15 05:57

    The typescript Document type is comparable to an SVGDocument, so you should be fine to just use Document. You will need to ensure that your element is casted as the right type (SVGElement or SVGSVGElement).

    Also, you can do double casting in Typescript. This may allow you to come up with a way to cast an element/document as any and back to the document/element type you need in the case that you run into further issues.

提交回复
热议问题