Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions test/types/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
{},
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