RobotWebTools / rclnodejs

Node.js version of ROS 2.0 client
https://docs.ros.org/en/jazzy/Concepts/Basic/About-Client-Libraries.html#community-maintained
Apache License 2.0
335 stars 72 forks source link

Types should support overloaded Node methods #873

Closed wayneparrott closed 2 years ago

wayneparrott commented 2 years 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>;