soimy / maxrects-packer

A max rectangle 2d bin packer npm-module for packing glyphs or images into multiple sprite-sheet/atlas

Home Page:https://soimy.github.io/maxrects-packer/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

addArray examples violate typescript types

JackCA opened this issue · comments

It appears that the addArray function only accepts types extended from IRectangle. This appears to be an issue because IRectangle includes values that should not be set during addition of rectangles (such as x and y).

e.g.

// packer: MaxRectsPacker<IRectangle>
packer.addArray([{width: 1, height: 1}]) // Type '{ width: number; height: number; }' is missing the following properties from type 'IRectangle': x, y ts(2739)

I think the generic needs to be more narrowed to something like

interface IRectangleInput {
  width: number
  height: number
  [propName: string]: any
}

perhaps porting the tests to typescript would catch this?

Thanks for making this lib either way 🙏

You are right, I'll look into it. Thx
As intended, addArray should accept any object with width & height

My fix was to use a Rectangle[]. The Rectangle constructor sets x and y to 0 by default and is happy to accept just width and height.