RobotWebTools / rclnodejs

Node.js version of ROS 2.0 client
https://docs.ros.org/en/humble/Concepts/Basic/About-Client-Libraries.html?highlight=rclnodejs#community-maintained
Apache License 2.0
311 stars 70 forks source link

Types should support overloaded Node methods #873

Closed wayneparrott closed 1 year ago

wayneparrott commented 1 year ago

The 2 JavaScript implementation of the Node methods, createSubscription() and createService() overload their options parameter such that it can either be an Options type or a callcaback function. The TypeScript declaration does not support this convenience. Therefore, I propose we added overloaded definitions for these 2 methods. The change will be similar to this:

// The new overloaded declaration that omits the options parameter
createSubscription<T extends TypeClass<MessageTypeClassName>>(
          typeClass: T,
          topic: string,
          callback: SubscriptionCallback<T>
): Subscription;

// The current declaration will remain as:
createSubscription<T extends TypeClass<MessageTypeClassName>>(
      typeClass: T,
      topic: string,
      options: Options,
      callback: SubscriptionCallback<T>
): Subscription;

// The new overloaded declaration that omits the options parameter
createService<T extends TypeClass<ServiceTypeClassName>>(
      typeClass: T,
      serviceName: string,
      callback: ServiceRequestHandler<T>
): ServiceType<T>;

// The current declaration will remain as:
createService<T extends TypeClass<ServiceTypeClassName>>(
      typeClass: T,
      serviceName: string,
      options: Options,
      callback: ServiceRequestHandler<T>
): ServiceType<T>;