Converting Javascript function to Typescript including getComputedTextLength()
One way could be to use assertion (i.e. we say to Typescript compiler - I know what is returned type here). So this could be solution
Instead of this:
while (word = words.pop()) { line.push(word); tspan.text(line.join(" ")); if (tspan.node().getComputedTextLength() > width) {
We could use this (e.g. here expecting that node should be SVGTSpanElement
)
while (word = words.pop()) { line.push(word); tspan.text(line.join(" ")); var node: SVGTSpanElement = <SVGTSpanElement>tspan.node(); var hasGreaterWidth = node.getComputedTextLength() > width; if (hasGreaterWidth) {
The 'SVGTSpanElement'
is coming from a common lib.d.ts