You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Infer concrete types from constructor TypeClass forms (#1526)
Support the constructor form of `TypeClass` (the value returned by `rclnodejs.require(...)`) with full type inference for messages, services, and actions, bringing it on par with the existing string and object-descriptor forms, and make the runtime loader accept that form so it works end to end.
## Types
- `TypeClass` now recognizes message, service (`{ Request, Response }`), and action (`{ Goal, Feedback, Result }`) constructor shapes (`types/node.d.ts`, `types/service.d.ts`, `types/action_client.d.ts`).
- `ServiceRequestMessage` / `ServiceResponseMessage` and `ActionGoal` / `ActionFeedback` / `ActionResult` infer the concrete payload types from the constructor.
- `ServiceType` / `ActionType` and the `rostsd_gen` generator (`rostsd_gen/index.js`) handle the constructor form.
## Runtime
- `lib/interface_loader.js`: `loadInterface()` accepts an already-loaded interface constructor and returns it as-is (idempotent), validated via the generated class's static `type()` method. Arbitrary functions still fall through to the existing `MESSAGE_NOT_FOUND` error. This fixes the `MESSAGE_NOT_FOUND` failure when a constructor was passed to `ActionServer` / `ActionClient`, which call `loadInterface` unconditionally.
## Tests
- `test/types/index.test-d.ts`: `tsd` coverage for every `TypeClass` form — message, service, and action via constructor, string, and object descriptor.
- `test/test-action-server.js`, `test/test-service.js`: runtime regression tests that pass the constructor form to `ActionServer` / `ActionClient` and `createService` / `createClient` and exercise a full round-trip.
- `test/test-message-type.js`: unit tests for `loadInterface()` idempotency and the arbitrary-function rejection path.
## Demos
- `topics`, `services`, and `actions` TypeScript demos updated to demonstrate both the string-name and message/service/action-class styles, with typed callbacks via `typeof Ctor`.
- All three demos depend on the local rclnodejs (`file:../../..`) and document `npm install --ignore-scripts`; README source examples use the current LTS (Lyrical).
Fix: #1525
0 commit comments