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

Enable useDefineForClassFields TS flag #7563

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

GytisCepk
Copy link
Contributor

TypeScript recommends setting useDefineForClassFields to true (default value starting ES2022). However, enabling this flag caused several issues. More info: #7474

Additionally, noticed that some TypeScript types are incorrectly defined (e.g. AuxCoordSystem2d.angle is defined as number, but in reality it can be a number, object or undefined). This PR fixes some of these.

@aruniverse
Copy link
Member

@wgoehrig when you get a chance, can you review this PR?

@wgoehrig wgoehrig self-assigned this Jan 22, 2025
Copy link
Contributor

mergify bot commented Jan 22, 2025

This pull request is now in conflicts. Could you fix it @GytisCepk? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

Comment on lines +661 to +664
this.origin = props.origin ? Point3d.fromJSON(props.origin) : undefined;
this.yaw = props.yaw ? Angle.fromJSON(props.yaw).degrees : undefined;
this.pitch = props.pitch ? Angle.fromJSON(props.pitch).degrees : undefined;
this.roll = props.roll ? Angle.fromJSON(props.roll).degrees : undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are nice fixes. Frankly I'm surprised that no one has hit this in all these years... Can you also add unit tests that exercise this so we can avoid regressions as we refactor all these Entity subclasses?

Comment on lines +621 to +622
this.type = props.type;
this.description = props.description;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For fields like these (where the type annotation already matches what the Entity constructor was setting), why not just use the declare keyword instead?

@@ -477,6 +477,7 @@ export abstract class GeometricElement extends Element {
super(props, iModel);
this.category = Id64.fromJSON(props.category);
this.geom = props.geom;
this.elementGeometryBuilderParams = props.elementGeometryBuilderParams;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class field is interesting... @GytisCepk were there any test or build failures that prompted you to add this?

I did some debugging and elementGeometryBuilderParams definitely is not set by the Entity constructor, and it also doesn't get serialized in GeometricElement.toJSON(). However, the corresponding GeometricElementProps.elementGeometryBuilderParams member is used in a bunch of places...

@pmconne @bbastings is it possible this class field is just broken and has never been used? Should we remove it entirely? If we want to fix it instead, we should probably also make sure it gets included in toJSON()...

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

Successfully merging this pull request may close these issues.

3 participants