Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addArray examples violate typescript types #46

Open
JackCA opened this issue Oct 1, 2022 · 2 comments
Open

addArray examples violate typescript types #46

JackCA opened this issue Oct 1, 2022 · 2 comments
Assignees

Comments

@JackCA
Copy link

JackCA commented Oct 1, 2022

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 🙏

@soimy
Copy link
Owner

soimy commented Nov 7, 2022

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

@soimy soimy self-assigned this Nov 7, 2022
@SkipHendriks
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants