Skip to content

Commit

Permalink
Added overload method declarations for node (#874)
Browse files Browse the repository at this point in the history
Added:
```
createSubscription()
createService()
```
  • Loading branch information
wayneparrott authored Aug 10, 2022
1 parent 4558425 commit 4ebb442
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
19 changes: 12 additions & 7 deletions test/types/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,19 +210,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',
{},
Expand Down
29 changes: 29 additions & 0 deletions types/node.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,21 @@ declare module 'rclnodejs' {
options?: Options
): Publisher<T>;

/**
* 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<T extends TypeClass<MessageTypeClassName>>(
typeClass: T,
topic: string,
callback: SubscriptionCallback<T>
): Subscription;

/**
* Create a Subscription.
*
Expand Down Expand Up @@ -278,6 +293,20 @@ declare module 'rclnodejs' {
options?: Options
): Client<T>;

/**
* 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<T extends TypeClass<ServiceTypeClassName>>(
typeClass: T,
serviceName: string,
callback: ServiceRequestHandler<T>
): ServiceType<T>;

/**
* Create a Service.
*
Expand Down

0 comments on commit 4ebb442

Please sign in to comment.