@@ -211,6 +211,24 @@ node.createPublisher(TYPE_CLASS, TOPIC, publisher.options, (event: object) => {
211211expectType < void > ( publisher . assertLiveliness ( ) ) ;
212212expectType < string > ( publisher . loggerName ) ;
213213
214+ // ---- TypeClass forms ----
215+ // Case 1: a message/service class constructor (e.g. the value returned by rclnodejs.require)
216+ const StringClass = rclnodejs . require ( 'std_msgs/msg/String' ) ;
217+ expectAssignable < rclnodejs . TypeClass > ( StringClass ) ;
218+ const publisherFromCtor = node . createPublisher ( StringClass , TOPIC ) ;
219+ expectType < rclnodejs . Publisher < typeof StringClass > > ( publisherFromCtor ) ;
220+
221+ // Case 2: a string representing the message class name
222+ expectAssignable < rclnodejs . TypeClass > ( TYPE_CLASS ) ;
223+ const publisherFromString = node . createPublisher ( TYPE_CLASS , TOPIC ) ;
224+ expectType < rclnodejs . Publisher < 'std_msgs/msg/String' > > ( publisherFromString ) ;
225+
226+ // Case 3: an object descriptor of the message class
227+ const typeDescriptor = { package : 'std_msgs' , type : 'msg' , name : 'String' } ;
228+ expectAssignable < rclnodejs . TypeClass > ( typeDescriptor ) ;
229+ const publisherFromDescriptor = node . createPublisher ( typeDescriptor , TOPIC ) ;
230+ expectType < rclnodejs . Publisher < typeof typeDescriptor > > ( publisherFromDescriptor ) ;
231+
214232// ---- LifecyclePublisher ----
215233const lifecyclePublisher = lifecycleNode . createLifecyclePublisher (
216234 TYPE_CLASS ,
@@ -343,6 +361,30 @@ expectType<void>(
343361expectType < boolean > ( client . isDestroyed ( ) ) ;
344362expectType < string > ( client . loggerName ) ;
345363
364+ // ---- Service/Client constructor-form typing ----
365+ // Passing a service constructor (the value returned by rclnodejs.require) should
366+ // infer the concrete request/response message types, not fall back to `object`.
367+ const AddTwoInts = rclnodejs . require ( 'example_interfaces/srv/AddTwoInts' ) ;
368+ const serviceFromCtor = node . createService (
369+ AddTwoInts ,
370+ 'add_two_ints_ctor' ,
371+ ( request ) => {
372+ expectType < rclnodejs . example_interfaces . srv . AddTwoInts_Request > ( request ) ;
373+ }
374+ ) ;
375+ expectType < rclnodejs . example_interfaces . srv . AddTwoIntsConstructor > (
376+ serviceFromCtor
377+ ) ;
378+
379+ const clientFromCtor = node . createClient ( AddTwoInts , 'add_two_ints_ctor' ) ;
380+ expectType < rclnodejs . Client < typeof AddTwoInts > > ( clientFromCtor ) ;
381+ clientFromCtor . sendRequest ( new AddTwoInts . Request ( ) , ( response ) => {
382+ expectType < rclnodejs . example_interfaces . srv . AddTwoInts_Response > ( response ) ;
383+ } ) ;
384+ expectType < Promise < rclnodejs . example_interfaces . srv . AddTwoInts_Response > > (
385+ clientFromCtor . sendRequestAsync ( new AddTwoInts . Request ( ) )
386+ ) ;
387+
346388// ---- Timer ----
347389const timerCallback : rclnodejs . TimerRequestCallback = ( timerInfo ) => {
348390 if ( timerInfo ) {
@@ -602,6 +644,25 @@ expectType<void>(
602644 )
603645) ;
604646
647+ // ---- Action constructor-form typing ----
648+ // Passing an action constructor (the value returned by rclnodejs.require) should
649+ // infer the concrete goal/feedback/result message types, not fall back to `object`.
650+ const actionClientFromCtor = new rclnodejs . ActionClient (
651+ node ,
652+ Fibonacci ,
653+ 'fibonacci_ctor'
654+ ) ;
655+ expectType < rclnodejs . ActionClient < typeof Fibonacci > > ( actionClientFromCtor ) ;
656+ expectType < rclnodejs . example_interfaces . action . Fibonacci_Goal > (
657+ { } as rclnodejs . ActionGoal < typeof Fibonacci >
658+ ) ;
659+ expectType < rclnodejs . example_interfaces . action . Fibonacci_Feedback > (
660+ { } as rclnodejs . ActionFeedback < typeof Fibonacci >
661+ ) ;
662+ expectType < rclnodejs . example_interfaces . action . Fibonacci_Result > (
663+ { } as rclnodejs . ActionResult < typeof Fibonacci >
664+ ) ;
665+
605666// ---- ActionUuid -----
606667const actionUuid = new rclnodejs . ActionUuid ( ) ;
607668expectType < rclnodejs . ActionUuid > ( actionUuid ) ;
0 commit comments