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

ZoomToFit Typescript issue #1280

Open
bruceborrett opened this issue Aug 17, 2023 · 6 comments
Open

ZoomToFit Typescript issue #1280

bruceborrett opened this issue Aug 17, 2023 · 6 comments

Comments

@bruceborrett
Copy link
Contributor

zoomToFit causes a typescript error saying that Geometry[] is not the correct type for the entities argument.

The return type of the function entitiesFromSolids is Geometry[] and zoomToFit is expecting this as input, so I assume this is a bug in the type declarations. If I change the zoomToFit function to expect Geometry[] then everything works as expected.

@platypii
Copy link
Contributor

It looks like you found a bug, but your suggested fix is backwards. The return type of entitiesFromSolids should actually be an array of entities, not an array of geometries. So the bug is in entitiesFromSolids.d.ts, whereas zoomToFit looks correct.

If you look at how it's used in practice, the data type is a list of entities, which contain geometry as one of the properties:

entities

Would you be willing to make a PR with a type definition fix?

@bruceborrett
Copy link
Contributor Author

Has the entity type been defined anywhere yet?

@platypii
Copy link
Contributor

I don't believe so. The closest is the inline type definition here for zoomToFit:

export function zoomToFit({ controls, camera, entities }: {

But I think it would be nicer if we defined the Entity type explicitly.

@bruceborrett
Copy link
Contributor Author

bruceborrett@5e6a792

Is something like this ok? Im not great with typescript and dont really understand the way that you have structured the types, perhaps you can guide me if Im way off.

@platypii
Copy link
Contributor

Yes that's looking very nice, pretty much the same way I would have done it. Notes:

  • the import in OrbitControls.d.ts needs to go to ../geometry-utils-V2/entity since its in an adjacent directory.
  • very minor style nit: I would add some line breaks in your entity.d.ts so that Entity is not all one long line.

Thanks for looking into this!

@bruceborrett
Copy link
Contributor Author

#1283

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

No branches or pull requests

2 participants