Skip to content

Conversation

@drewhoener
Copy link
Contributor

@drewhoener drewhoener commented Nov 14, 2025

Public API Changes
None

Description
While the typing work was extensive to represent the RosBridge protocol, there were some things that were overlooked in the migration that meant that the type checking both for the developers of this library, and the types delivered to developers working with the lib weren't exhaustive.
This PR addresses this by refactoring the protocol files:

  • Add the documentation from the ROSBridge protocol doc to aid developers which took forever but is worth it (at least for me)
  • Create union types both for subsections of the protocol, but also every possible operation. This means that type checking can be narrowed just by checking the 'op' field without having to have a guard method for each operation.
  • Fixes some discrepancies that arose as a result of the non-exhaustive checking.
  • Allows a distinction between outgoing and incoming service call messages, which takes care of the TODO left by Ezra w.r.t being deep partial on the way out but required on the way in.
  • Allows inference on emitter types for special name topic strings like service call and action callback messages.

Apologies for the name changes, I had this left over from another PR I didn't get to complete and the scheme was completely different from yours.

This PR also does some housekeeping on complex methods with large Cyclomatic Complexity, making them easier to read and maintain. In particular, Service#advertise and advertiseAsync have a common parent function now, joining the common parts together.

I also split out some of the longer that were declared right in function parameters, which makes them harder to read and follow when you have a large object in the constructor.

As always, thanks for the consideration and happy to address any comments :)

Fixes #1068
Fixes #1069

…tion based on the Rosbridge Protocol

Signed-off-by: Drew Hoener <[email protected]>
…d on "op" field instead of all the checker functions. Enforce typing of messages and callback types. Fix deviations from protocol spec

Signed-off-by: Drew Hoener <[email protected]>
… objects. Add helper types to increase readability in constructors and function parameters.

Signed-off-by: Drew Hoener <[email protected]>
…lomatic Complexity and increase readability.

Signed-off-by: Drew Hoener <[email protected]>
Copy link
Collaborator

@EzraBrooks EzraBrooks left a comment

Choose a reason for hiding this comment

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

Could you break this down into more atomic PRs? I'm finding it hard to determine which changes are related to which.

* @param obj The object to check.
* @param prop The property to check for.
*/
export function hasOwn<X extends object, Y extends PropertyKey>(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you know the in operator already does this type guard?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in will also check the prototype chain which isn't always something you want. Though for the places I use it I suppose I could just use in

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep - however, given that we have no inheritance other than from Object on these messages, I think it's fine

RosActionEvents & // Action Events
RosServiceEvents &
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Record<TopicKey, [message: any]>; // Service Calls & Topic messages, need to be `any` to be coerced by implementers
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please use unknown instead of any.

@EzraBrooks
Copy link
Collaborator

I had a brain blast on how to (tediously, but thoroughly) strictly enforce the message types everywhere. I'll put up a PR for your review

@EzraBrooks
Copy link
Collaborator

please let me know what you think about #1075 - it caught the issue you reported with Service, plus a couple others

@drewhoener
Copy link
Contributor Author

Superseded by #1075, I'll open different PRs to address my other maintainability changes

@drewhoener drewhoener closed this Nov 14, 2025
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.

Inconsistent impl of Rosbridge Protocol in Service class Suspicious bind call in Action class

2 participants