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

prettyPrintGtfsEntityField: fix types #7316

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pjonsson
Copy link
Contributor

What this PR does

Running yarn upgrade gives a type error
for something with loadash-es, so add
a default value and fix a type annotation
to include undefined.

Test me

I believe this is tested by CI.

Checklist

  • There are unit tests to verify my changes are correct or unit tests aren't applicable (if so, write quick reason why unit tests don't exist)
  • I've updated relevant documentation in doc/.
  • I've updated CHANGES.md with what I changed.
  • I've provided instructions in the PR description on how to test this PR.

pjonsson referenced this pull request Nov 25, 2024
Mainly implements a workaround for error TS2855 that prevents accessing parent class
fields as `super.field` [introduced in TS
5.3](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-3.html#checks-for-super-property-accesses-on-instance-fields). In
valid JS, super can only be used to access get/set accessors or methods from
parent classes that are declared on the prototype, but not instance
fields (declared as `x = "something"`). In our case though, traits are declared
as getters and not fields, however because we use mapped types to mixin the
traits into a class and mapped types does not allow specifying getter/setter
variants, TS considers our traits to be fields and raises TS2855.

The workaround in this PR defines these erroring traits as getters which seems
to convince TS (at least for now) that they are valid accessors eventhough they
still are typed using mapped.

Hopefully in the future, we get this TS feature implementing [variant accessors
for mapped types](microsoft/TypeScript#43826), then
we can get rid of this workaround.
Comment on lines 12 to 13
const route: string = _get(entity, "vehicle.trip.route_id", "");
if (route !== undefined && route.indexOf("_") + 1 > 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think because it is checking for route !== undefined - the safer change would be to type it as route: string | undefined (similar to what you have done below) - instead of passing a default empty string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm pretty sure I tried that first and it didn't work, but let's go with that for now. Fixed.

Running yarn upgrade gives a type error
for something with loadash-es, so add
a default value and fix a type annotation
to include undefined.
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.

2 participants