svgdotjs/svg.js

Incomplete typings - measurements should accept percentages

cyberwombat opened this issue · 3 comments

Bug report

I am converting project to TS and in my case the rect method doesn't accept percentages.

 const element = svg.rect('100%', '100%') 

Yields a TS error of "Agument of type 'string' is not assignable to parameter of type 'number'."
I can make a fiddle if necessary but I think it's pretty clear. The TS definitions for all the shapes should accept strings as well.

Triangle in a square hole!

I'm sure you're aware, but you can instead use a relative dimensional calculation if you're stuck on this. Pain in the butt, though, they should fix this to match JS.

const svgWidth = svg.viewbox().width;
const svgHeight = svg.viewbox().height;

const element = svg.rect(svgWidth, svgHeight);

Thanks that's a nice workaround. Was gonna extend the typings locally but struggling a bit with it so gonna use your suggestion

fixed in 3f623a9