diff --git a/test/types/main.ts b/test/types/main.ts index 038edf28..f1decddf 100644 --- a/test/types/main.ts +++ b/test/types/main.ts @@ -193,19 +193,24 @@ lifecyclePublisher.isActivated(); // ---- Subscription ---- // $ExpectType Subscription -const subscription = node.createSubscription( - TYPE_CLASS, - TOPIC, - {}, - (msg) => {} -); +let subscription = node.createSubscription(TYPE_CLASS, TOPIC, (msg) => {}); + +// $ExpectType Subscription +subscription = node.createSubscription(TYPE_CLASS, TOPIC, {}, (msg) => {}); // $ExpectType string subscription.topic; // ---- Service ---- // $ExpectType AddTwoIntsConstructor -const service = node.createService( +let service = node.createService( + 'example_interfaces/srv/AddTwoInts', + 'add_two_ints', + (request, response) => {} +); + +// $ExpectType AddTwoIntsConstructor +service = node.createService( 'example_interfaces/srv/AddTwoInts', 'add_two_ints', {}, diff --git a/types/node.d.ts b/types/node.d.ts index bdf34e8a..2cd1c547 100644 --- a/types/node.d.ts +++ b/types/node.d.ts @@ -248,6 +248,21 @@ declare module 'rclnodejs' { options?: Options ): Publisher; + /** + * Create a Subscription. + * + * @param typeClass - Type of ROS messages the subscription will subscribe to + * @param topic - Name of the topic the subcription will subscribe to. + * @param callback - Called when a new message is received. + * The serialized message will be null-terminated. + * @returns New instance of Subscription. + */ + createSubscription>( + typeClass: T, + topic: string, + callback: SubscriptionCallback + ): Subscription; + /** * Create a Subscription. * @@ -278,6 +293,20 @@ declare module 'rclnodejs' { options?: Options ): Client; + /** + * Create a Service. + * + * @param typeClass - Service type + * @param serviceName - Name of the service. + * @param callback - Callback function for notification of incoming requests. + * @returns An instance of Service. + */ + createService>( + typeClass: T, + serviceName: string, + callback: ServiceRequestHandler + ): ServiceType; + /** * Create a Service. *