svgdotjs / svg.js

The lightweight library for manipulating and animating SVG
https://svgjs.dev
Other
10.95k stars 1.07k forks source link

Incomplete typings - measurements should accept percentages #1306

Closed cyberwombat closed 10 months ago

cyberwombat commented 11 months ago

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.

elliottmejia commented 11 months ago

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);
cyberwombat commented 11 months ago

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

Fuzzyma commented 10 months ago

fixed in https://github.com/svgdotjs/svg.js/commit/3f623a9e61a9015ceef3735bca167e9410313e49