From 7e877fa79e106f551aed530ea69ca9b9e7d1a161 Mon Sep 17 00:00:00 2001 From: Minggang Wang Date: Fri, 28 Feb 2025 16:32:10 +0800 Subject: [PATCH] Replace dtslint with tsd to test .d.ts files --- package.json | 19 +- test/types/index.d.ts | 1 - test/types/index.test-d.ts | 392 +++++++++++++++++++++ test/types/main.ts | 696 ------------------------------------- test/types/test.ts | 20 -- test/types/tsconfig.json | 17 - test/types/tslint.json | 11 - 7 files changed, 403 insertions(+), 753 deletions(-) delete mode 100644 test/types/index.d.ts create mode 100644 test/types/index.test-d.ts delete mode 100644 test/types/main.ts delete mode 100644 test/types/test.ts delete mode 100644 test/types/tsconfig.json delete mode 100644 test/types/tslint.json diff --git a/package.json b/package.json index a0e65f7f..24420ae1 100644 --- a/package.json +++ b/package.json @@ -17,14 +17,13 @@ "build:dev": "node-gyp -j 16 build --debug", "rebuild": "npm run clean && node-gyp -j 16 rebuild", "rebuild:dev": "npm run clean && node-gyp -j 16 rebuild --debug", - "generate-messages": "node scripts/generate_messages.js", - "generate-messages:dev": "node scripts/generate_messages.js --debug", + "generate-messages": "node scripts/generate_messages.js && node scripts/generate_tsd.js", + "generate-messages:dev": "node scripts/generate_messages.js --debug && node scripts/generate_tsd.js", "clean": "node-gyp clean && rimraf ./generated", "install": "npm run rebuild", "postinstall": "npm run generate-messages", "docs": "cd docs && make", - "test": "node --expose-gc ./scripts/run_test.js && npm run dtslint", - "dtslint": "node scripts/generate_tsd.js", + "test": "node --expose-gc ./scripts/run_test.js && npx tsd", "lint": "eslint --max-warnings=0 --ext js,ts index.js types scripts lib example rosidl_gen rosidl_parser test benchmark/rclnodejs && node ./scripts/cpplint.js", "format": "clang-format -i -style=file ./src/*.cpp ./src/*.hpp && prettier --write \"{lib,rosidl_gen,rostsd_gen,rosidl_parser,types,example,test,scripts,benchmark}/**/*.{js,md,ts}\" ./*.{js,md,ts}", "prepare": "husky" @@ -45,6 +44,7 @@ }, "devDependencies": { "@babel/eslint-parser": "^7.25.9", + "@types/node": "^22.13.5", "@typescript-eslint/eslint-plugin": "^8.18.0", "@typescript-eslint/parser": "^8.18.0", "babel-eslint": "^10.1.0", @@ -60,6 +60,7 @@ "mocha": "^11.0.2", "sinon": "^19.0.2", "tree-kill": "^1.2.2", + "tsd": "^0.31.2", "typescript": "^5.7.2" }, "dependencies": { @@ -70,17 +71,16 @@ "compare-versions": "^6.1.1", "debug": "^4.4.0", "dot": "^1.1.3", - "dtslint": "^4.2.1", "fs-extra": "^11.2.0", - "json-bigint": "^1.0.0", "is-close": "^1.3.3", + "json-bigint": "^1.0.0", "mkdirp": "^3.0.1", "mz": "^2.7.0", "nan": "^2.22.0", + "prettier": "^3.4.2", "rimraf": "^6.0.1", "uuid": "^11.0.3", - "walk": "^2.3.15", - "prettier": "^3.4.2" + "walk": "^2.3.15" }, "husky": { "hooks": { @@ -95,6 +95,9 @@ "clang-format -i -style=file" ] }, + "tsd": { + "directory": "test/types" + }, "engines": { "node": ">= 16.13.0" } diff --git a/test/types/index.d.ts b/test/types/index.d.ts deleted file mode 100644 index ed97e6f6..00000000 --- a/test/types/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -// Minimum TypeScript Version: 3.9 diff --git a/test/types/index.test-d.ts b/test/types/index.test-d.ts new file mode 100644 index 00000000..7597ccd8 --- /dev/null +++ b/test/types/index.test-d.ts @@ -0,0 +1,392 @@ +/// + +import { expectType } from 'tsd'; +import * as rclnodejs from 'rclnodejs'; + +const NODE_NAME = 'test_node'; +const LIFECYCLE_NODE_NAME = 'lifecycle_test_node'; +const TYPE_CLASS = 'std_msgs/msg/String'; +const TOPIC = 'topic'; +const MSG = rclnodejs.createMessageObject(TYPE_CLASS); +MSG.data = ''; + +// ---- rclnodejs ----- +expectType>(rclnodejs.init()); +expectType(rclnodejs.DistroUtils.getDistroName()); +expectType(rclnodejs.isShutdown()); +expectType(rclnodejs.shutdown()); +expectType(rclnodejs.removeSignalHandlers()); + +// ---- DistroUtil ---- +expectType(rclnodejs.DistroUtils.getDistroId()); +expectType( + rclnodejs.DistroUtils.getDistroId('foxy') +); +expectType(rclnodejs.DistroUtils.getDistroName()); +expectType(rclnodejs.DistroUtils.getDistroName(2105)); + +// ---- Context ----- +expectType(rclnodejs.Context.defaultContext()); + +// ---- NodeOptions ---- +const nodeOptions = new rclnodejs.NodeOptions(); +expectType(nodeOptions); +expectType(nodeOptions.startParameterServices); +expectType(nodeOptions.automaticallyDeclareParametersFromOverrides); +expectType(nodeOptions.parameterOverrides); + +// ---- Node ----- +const node = rclnodejs.createNode(NODE_NAME); +expectType(node); +expectType(new rclnodejs.Node(NODE_NAME + '1')); +expectType(node.name()); +expectType(node.namespace()); +expectType(node.getLogger()); +expectType(node.getClock()); +expectType(node.spin()); +expectType(node.spinOnce()); +expectType(node.spinning); +expectType(node.destroy()); +expectType( + node.getPublisherNamesAndTypesByNode(NODE_NAME) +); +expectType( + node.getServiceNamesAndTypes() +); +expectType( + node.getServiceNamesAndTypesByNode(NODE_NAME) +); +expectType( + node.getSubscriptionNamesAndTypesByNode(NODE_NAME) +); +expectType(node.getTopicNamesAndTypes()); +expectType(node.getNodeNames()); +expectType(node.getNodeNamesAndNamespaces()); +expectType(node.countPublishers(TOPIC)); +expectType(node.countSubscribers(TOPIC)); +expectType>( + rclnodejs.Node.getDefaultOptions() +); + +// ---- LifecycleNode ---- +const lifecycleNode = rclnodejs.createLifecycleNode(LIFECYCLE_NODE_NAME); +expectType(lifecycleNode); + +const lifecycleNode1 = rclnodejs.createLifecycleNode( + LIFECYCLE_NODE_NAME + '1', + undefined, + undefined, + undefined, + true +); +expectType(lifecycleNode1); + +const lifecycleNode2 = new rclnodejs.lifecycle.LifecycleNode( + LIFECYCLE_NODE_NAME +); +expectType(lifecycleNode2); + +const lifecycleNode3 = new rclnodejs.lifecycle.LifecycleNode( + LIFECYCLE_NODE_NAME + '3', + undefined, + undefined, + undefined, + true +); +expectType(lifecycleNode3); + +expectType(lifecycleNode.currentState); +expectType(lifecycleNode.availableStates); +expectType( + lifecycleNode.transitions +); +expectType( + lifecycleNode.availableTransitions +); + +const ReturnValue = new rclnodejs.lifecycle.CallbackReturnValue(); +expectType(ReturnValue); +expectType(lifecycleNode.configure(ReturnValue)); +expectType(lifecycleNode.activate()); +expectType(lifecycleNode.deactivate()); +expectType(lifecycleNode.cleanup()); +expectType(lifecycleNode.shutdown()); + +// ---- Publisher ---- +const publisher = node.createPublisher(TYPE_CLASS, TOPIC); +expectType>(publisher); +expectType(publisher.options); +expectType(publisher.qos); +expectType(publisher.topic); +expectType>(publisher.typeClass); +expectType(publisher.typedArrayEnabled); +expectType(publisher.publish(MSG)); +expectType(publisher.publish(Buffer.from('Hello ROS World'))); +expectType(node.destroyPublisher(publisher)); +expectType(publisher.isDestroyed()); + +// ---- LifecyclePublisher ---- +const lifecyclePublisher = lifecycleNode.createLifecyclePublisher( + TYPE_CLASS, + TOPIC +); +expectType>( + lifecyclePublisher +); +expectType(lifecyclePublisher.isActivated()); + +// ---- Subscription ---- +let subscription = node.createSubscription(TYPE_CLASS, TOPIC, () => {}); +expectType(subscription); +expectType( + node.createSubscription(TYPE_CLASS, TOPIC, {}, () => {}) +); + +const contentFilter: rclnodejs.SubscriptionContentFilter = { + expression: 'data < %0', + parameters: [5], +}; + +subscription = node.createSubscription( + TYPE_CLASS, + TOPIC, + { contentFilter }, + () => {} +); +expectType(subscription); + +subscription = node.createSubscription( + TYPE_CLASS, + TOPIC, + { isRaw: false }, + (message: rclnodejs.std_msgs.msg.String) => { + const receivedMessage = message; + } +); + +const rawMessageCallback = (message: Buffer) => { + const receivedRawMessage = message; +}; +expectType(rawMessageCallback); + +expectType(subscription.topic); +expectType(subscription.isDestroyed()); +expectType(subscription.setContentFilter(contentFilter)); +expectType(subscription.clearContentFilter()); +expectType(subscription.hasContentFilter()); + +// ---- Service ---- +const service = node.createService( + 'example_interfaces/srv/AddTwoInts', + 'add_two_ints', + () => {} +); +expectType(service); + +expectType(service.serviceName); +expectType(service.options); +expectType( + service.configureIntrospection( + node.getClock(), + rclnodejs.Node.getDefaultOptions() as rclnodejs.QoS, + rclnodejs.ServiceIntrospectionStates.CONTENTS + ) +); +expectType(service.isDestroyed()); + +// ---- Client ---- +const client = node.createClient( + 'example_interfaces/srv/AddTwoInts', + 'add_two_ints' +); +expectType>(client); +expectType(client.serviceName); +expectType(client.isServiceServerAvailable()); +expectType>(client.waitForService()); +expectType( + client.configureIntrospection( + node.getClock(), + rclnodejs.Node.getDefaultOptions() as rclnodejs.QoS, + rclnodejs.ServiceIntrospectionStates.CONTENTS + ) +); +expectType(client.isDestroyed()); + +// ---- Timer ---- +const timerCallback = () => {}; +expectType(timerCallback); + +const timer = node.createTimer(BigInt(100000), timerCallback); +expectType(timer); +expectType(timer.period); +expectType(timer.isReady()); +expectType(timer.timeSinceLastCall()); +expectType(timer.timeUntilNextCall()); +expectType(timer.isCanceled()); +expectType(timer.cancel()); + +// ---- Rate ---- +const rate = await node.createRate(1); +expectType(rate); +expectType(rate.frequency); +expectType(rate.isCanceled()); +expectType>(rate.sleep()); +expectType(rate.cancel()); + +// ---- Duration ---- +const duration1 = new rclnodejs.Duration(); +expectType(duration1); + +const duration2 = new rclnodejs.Duration(BigInt(100), BigInt(1000)); +expectType(duration2); +expectType(duration1.nanoseconds); +expectType(duration1.eq(duration2)); +expectType(duration1.ne(duration2)); +expectType(duration1.lt(duration2)); +expectType(duration1.lte(duration2)); +expectType(duration1.gt(duration2)); +expectType(duration1.gte(duration2)); + +// ---- Time ---- +const time1 = new rclnodejs.Time(BigInt(100), BigInt(100)); +expectType(time1); + +const time2 = rclnodejs.Time.fromMsg({ sec: 0, nanosec: 0 }); +expectType(time2); + +const time3 = rclnodejs.Time.fromMsg( + { sec: 0, nanosec: 0 }, + rclnodejs.ClockType.ROS_TIME +); +expectType(time3); + +expectType(time1.clockType); +expectType(time1.nanoseconds); +expectType<{ seconds: bigint; nanoseconds: bigint }>( + time1.secondsAndNanoseconds +); +expectType(time1.add(duration1)); +expectType(time1.eq(time2)); +expectType(time1.ne(time2)); +expectType(time1.lt(time2)); +expectType(time1.lte(time2)); +expectType(time1.gt(time2)); +expectType(time1.gte(time2)); +expectType(time3.toMsg()); + +// ---- Clock ----- +const clock = new rclnodejs.Clock(rclnodejs.ClockType.SYSTEM_TIME); +expectType(clock); +expectType(clock.clockType); +expectType(clock.now()); + +// ---- Logging ----- +const logger = rclnodejs.Logging.getLogger('test_logger'); +expectType(logger); +expectType(logger.name); +expectType(logger.loggerEffectiveLevel); +expectType(logger.setLoggerLevel(rclnodejs.Logging.LoggingSeverity.INFO)); +expectType(logger.debug('test msg')); +expectType(logger.info('test msg')); +expectType(logger.debug('test msg')); +expectType(logger.warn('test msg')); +expectType(logger.error('test msg')); +expectType(logger.fatal('test msg')); + +// ---- ActionClient ----- +const Fibonacci = rclnodejs.require('example_interfaces/action/Fibonacci'); +expectType(Fibonacci); + +const actionClient = new rclnodejs.ActionClient( + node, + 'example_interfaces/action/Fibonacci', + 'fibonnaci' +); +expectType>( + actionClient +); +expectType(client.isServiceServerAvailable()); +expectType>(actionClient.waitForServer()); +expectType(actionClient.destroy()); + +const goalHandlePromise = actionClient.sendGoal(new Fibonacci.Goal()); +expectType< + Promise> +>(goalHandlePromise); + +goalHandlePromise.then((goalHandle) => { + expectType(goalHandle.accepted); + expectType(goalHandle.goalId); + expectType(goalHandle.stamp); + expectType(goalHandle.status); + expectType>( + goalHandle.cancelGoal() + ); + expectType>( + goalHandle.getResult() + ); + expectType(goalHandle.isAccepted()); + expectType(goalHandle.isExecuting()); + expectType(goalHandle.isSucceeded()); + expectType(goalHandle.isCanceling()); + expectType(goalHandle.isCanceled()); + expectType(goalHandle.isAborted()); +}); + +// ---- ActionServer ----- +const actionServer = new rclnodejs.ActionServer( + node, + 'example_interfaces/action/Fibonacci', + 'fibonacci', + executeCallback +); +expectType>( + actionServer +); +expectType(actionServer.registerHandleAcceptedCallback()); +expectType(actionServer.registerGoalCallback()); +expectType(actionServer.registerCancelCallback()); +expectType( + actionServer.registerExecuteCallback(() => new Fibonacci.Result()) +); +expectType(actionServer.destroy()); + +function executeCallback( + goalHandle: rclnodejs.ServerGoalHandle<'example_interfaces/action/Fibonacci'> +) { + expectType(goalHandle.goalId); + expectType(goalHandle.isActive); + expectType(goalHandle.isCancelRequested); + expectType( + goalHandle.request + ); + expectType(goalHandle.status); + expectType(goalHandle.abort()); + expectType(goalHandle.canceled()); + expectType(goalHandle.execute()); + expectType(goalHandle.publishFeedback(new Fibonacci.Feedback())); + expectType(goalHandle.succeed()); + + return new Fibonacci.Result(); +} + +// ---- ActionUuid ----- +const actionUuid = new rclnodejs.ActionUuid(); +expectType(actionUuid); +expectType(rclnodejs.ActionUuid.random()); +expectType( + rclnodejs.ActionUuid.fromBytes(new Uint8Array([21, 31])) +); +expectType(actionUuid.toString()); +expectType(actionUuid.toMessage()); +expectType( + rclnodejs.ActionUuid.randomMessage() +); + +// ---- Parameter ----- +const param = rclnodejs.createMessageObject('rcl_interfaces/msg/Parameter'); +expectType(param); +param.value.integer_value = BigInt(123); +expectType(param.value.integer_value); +param.value.byte_array_value = [1, 2, 3]; +expectType(param.value.byte_array_value); diff --git a/test/types/main.ts b/test/types/main.ts deleted file mode 100644 index a05f471f..00000000 --- a/test/types/main.ts +++ /dev/null @@ -1,696 +0,0 @@ -/// -import * as rclnodejs from 'rclnodejs'; - -const NODE_NAME = 'test_node'; -const LIFECYCLE_NODE_NAME = 'lifecycle_test_node'; -const TYPE_CLASS = 'std_msgs/msg/String'; -const TOPIC = 'topic'; -const MSG = rclnodejs.createMessageObject(TYPE_CLASS); -MSG.data = ''; - -// ---- rclnodejs ----- -// $ExpectType Promise -rclnodejs.init(); - -// $ExpectType Promise -rclnodejs.init(rclnodejs.Context.defaultContext()); - -// $ExpectType boolean -rclnodejs.isShutdown(); - -// $ExpectType void -rclnodejs.shutdown(); - -// $ExpectType void -rclnodejs.removeSignalHandlers(); - -// ---- DistroUtil ---- - -// $ExpectType DistroId -rclnodejs.DistroUtils.getDistroId(); - -// $ExpectType DistroId -rclnodejs.DistroUtils.getDistroId('foxy'); - -// $ExpectType string | undefined -rclnodejs.DistroUtils.getDistroName(); - -// $ExpectType string | undefined -rclnodejs.DistroUtils.getDistroName(2105); - -// ---- Context ----- -// $ExpectType Context -const context = rclnodejs.Context.defaultContext(); - -// ---- NodeOptions ---- -// $ExpectType NodeOptions -const nodeOptions = new rclnodejs.NodeOptions(); - -// $ExpectType boolean -nodeOptions.startParameterServices; - -// $ExpectType boolean -nodeOptions.automaticallyDeclareParametersFromOverrides; - -// $ExpectType Parameter[] -nodeOptions.parameterOverrides; - -// ---- Node ----- -// $ExpectType Node -const node = rclnodejs.createNode(NODE_NAME); - -// $ExpectType Node -const node1 = new rclnodejs.Node(NODE_NAME + '1'); - -// $ExpectType string -node.name(); - -// $ExpectType string -node.namespace(); - -// $ExpectType Logging -node.getLogger(); - -// $ExpectType Clock -node.getClock(); - -// $ExpectType void -node.spin(); - -// $ExpectType void -node.spinOnce(); - -// $ExpectType boolean -node.spinning; - -// $ExpectType void -node.destroy(); - -// $ExpectType NamesAndTypesQueryResult[] -node.getPublisherNamesAndTypesByNode(NODE_NAME); - -// $ExpectType NamesAndTypesQueryResult[] -node.getServiceNamesAndTypes(); - -// $ExpectType NamesAndTypesQueryResult[] -node.getServiceNamesAndTypesByNode(NODE_NAME); - -// $ExpectType NamesAndTypesQueryResult[] -node.getSubscriptionNamesAndTypesByNode(NODE_NAME); - -// $ExpectType NamesAndTypesQueryResult[] -node.getTopicNamesAndTypes(); - -// $ExpectType string[] -node.getNodeNames(); - -// $ExpectType NodeNamesQueryResult[] -node.getNodeNamesAndNamespaces(); - -// $ExpectType number -node.countPublishers(TOPIC); - -// $ExpectType number -node.countSubscribers(TOPIC); - -// $ExpectType Options -rclnodejs.Node.getDefaultOptions(); - -// ---- LifecycleNode ---- -// $ExpectType LifecycleNode -const lifecycleNode = rclnodejs.createLifecycleNode(LIFECYCLE_NODE_NAME); - -// $ExpectType LifecycleNode -const lifecycleNode1 = rclnodejs.createLifecycleNode( - LIFECYCLE_NODE_NAME + '1', - undefined, - undefined, - undefined, - true -); - -// $ExpectType LifecycleNode -const lifecycleNode2 = new rclnodejs.lifecycle.LifecycleNode( - LIFECYCLE_NODE_NAME -); - -// $ExpectType LifecycleNode -const lifecycleNode3 = new rclnodejs.lifecycle.LifecycleNode( - LIFECYCLE_NODE_NAME + '3', - undefined, - undefined, - undefined, - true -); - -// $ExpectType State -lifecycleNode.currentState; - -// $ExpectType State[] -lifecycleNode.availableStates; - -// $ExpectType TransitionDescription[] -lifecycleNode.transitions; - -// $ExpectType TransitionDescription[] -lifecycleNode.availableTransitions; - -//// $ExpectType TransitionCallback -// const lifecycleCB: TransitionCallback = (prevState: State) => CallbackReturnCode.SUCCESS; - -// $ExpectType CallbackReturnValue -const ReturnValue = new rclnodejs.lifecycle.CallbackReturnValue(); - -// $ExpectType State -lifecycleNode.configure(ReturnValue); - -// $ExpectType State -lifecycleNode.activate(); - -// $ExpectType State -lifecycleNode.deactivate(); - -// $ExpectType State -lifecycleNode.cleanup(); - -// $ExpectType State -lifecycleNode.shutdown(); - -// ---- Publisher ---- -// $ExpectType Publisher<"std_msgs/msg/String"> -const publisher = node.createPublisher(TYPE_CLASS, TOPIC); - -// $ExpectType object -publisher.options; - -// $ExpectType QoS -publisher.qos; - -// $ExpectType string -publisher.topic; - -// $ExpectType TypeClass -publisher.typeClass; - -// $ExpectType boolean -publisher.typedArrayEnabled; - -// $ExpectType void -publisher.publish(MSG); - -// $ExpectType void -publisher.publish(Buffer.from('Hello ROS World')); - -// $ExpectType void -node.destroyPublisher(publisher); - -// $ExpectType boolean -publisher.isDestroyed(); - -// ---- LifecyclePublisher ---- -// $ExpectType LifecyclePublisher<"std_msgs/msg/String"> -const lifecyclePublisher = lifecycleNode.createLifecyclePublisher( - TYPE_CLASS, - TOPIC -); - -// $ExpectType boolean -lifecyclePublisher.isActivated(); - -// ---- Subscription ---- -// $ExpectType Subscription -let subscription = node.createSubscription(TYPE_CLASS, TOPIC, (msg) => {}); - -// $ExpectType Subscription -subscription = node.createSubscription(TYPE_CLASS, TOPIC, {}, (msg) => {}); - -const contentFilter: rclnodejs.SubscriptionContentFilter = { - expression: 'data < %0', - parameters: [5], -}; - -// $ExpectType Subscription -subscription = node.createSubscription( - TYPE_CLASS, - TOPIC, - { contentFilter }, - (msg) => {} -); - -// $ExpectType Subscription -subscription = node.createSubscription( - TYPE_CLASS, - TOPIC, - { isRaw: false }, - (message: rclnodejs.std_msgs.msg.String) => { - const receivedMessage = message; - } -); - -// $ExpectType Subscription receiving raw message -subscription = node.createSubscription( - TYPE_CLASS, - TOPIC, - { isRaw: true }, - (message: Buffer) => { - const receivedRawMessage = message; - } -); - -// $ExpectType string -subscription.topic; - -// $ExpectType boolean -subscription.isDestroyed(); - -subscription.setContentFilter(contentFilter); - -// $ExpectType boolean -subscription.clearContentFilter(); - -// $ExpectType boolean -subscription.hasContentFilter(); - -// ---- Service ---- -// $ExpectType AddTwoIntsConstructor -const service = node.createService( - 'example_interfaces/srv/AddTwoInts', - 'add_two_ints', - (request, response) => {} -); - -// $ExpectType string -service.serviceName; - -// $ExpectType object -service.options; - -service.configureIntrospection( - node.getClock(), - rclnodejs.Node.getDefaultOptions() as rclnodejs.QoS, - rclnodejs.ServiceIntrospectionStates.CONTENTS -); - -// $ExpectType boolean -service.isDestroyed(); - -// ---- Client ---- -// $ExpectType Client<"example_interfaces/srv/AddTwoInts"> -const client = node.createClient( - 'example_interfaces/srv/AddTwoInts', - 'add_two_ints' -); - -// $ExpectType string -client.serviceName; - -// $ExpectType boolean -client.isServiceServerAvailable(); - -// $ExpectType Promise -client.waitForService(); - -client.configureIntrospection( - node.getClock(), - rclnodejs.Node.getDefaultOptions() as rclnodejs.QoS, - rclnodejs.ServiceIntrospectionStates.CONTENTS -); - -// $ExpectType boolean -client.isDestroyed(); - -// ---- Timer ---- -// ExpectType rclnodejs.TimerRequestCallback -const timerCallback = () => {}; - -// $ExpectType Timer -const timer = node.createTimer(BigInt(100000), timerCallback); - -// $ExpectType bigint -timer.period; - -// $ExpectType boolean -timer.isReady(); - -// $ExpectType bigint -timer.timeSinceLastCall(); - -// $ExpectType bigint -timer.timeUntilNextCall(); - -// $ExpectType boolean -timer.isCanceled(); - -// $ExpectType void -timer.cancel(); - -(async () => { - // ---- Rate ---- - // $ExpectType Rate - const rate = await node.createRate(1); - - // $ExpectType number - rate.frequency; - - // $ExpectType boolean - rate.isCanceled(); - - // $ExpectType Promise - rate.sleep(); - - // $ExpectType void - rate.cancel(); -})(); - -// ---- Duration ---- -// $ExpectType Duration -const duration1: rclnodejs.Duration = new rclnodejs.Duration(); - -const duration2: rclnodejs.Duration = new rclnodejs.Duration( - BigInt(100), - BigInt(1000) -); - -// $ExpectType bigint -duration1.nanoseconds; - -// $ExpectType boolean -duration1.eq(duration2); - -// $ExpectType boolean -duration1.ne(duration2); - -// $ExpectType boolean -duration1.lt(duration2); - -// $ExpectType boolean -duration1.lte(duration2); - -// $ExpectType boolean -duration1.gt(duration2); - -// $ExpectType boolean -duration1.gte(duration2); - -// ---- Time ---- -// $ExpectType Time -const time1 = new rclnodejs.Time(BigInt(100), BigInt(100)); - -// $ExpectType Time -const time2 = rclnodejs.Time.fromMsg({ sec: 0, nanosec: 0 }); - -// $ExpectType Time -const time3 = rclnodejs.Time.fromMsg( - { sec: 0, nanosec: 0 }, - rclnodejs.ClockType.ROS_TIME -); - -// $ExpectType ClockType -time1.clockType; - -// $ExpectType bigint -time1.nanoseconds; - -// $ExpectType { seconds: bigint; nanoseconds: bigint; } -time1.secondsAndNanoseconds; - -// $ExpectType Time -time1.add(duration1); - -// TODO: wayne - readd the 2 failing expect cases for Time|Duration transposed failure - -// $ExpectType boolean -time1.eq(time2); - -// $ExpectType boolean -time1.ne(time2); - -// $ExpectType boolean -time1.lt(time2); - -// $ExpectType boolean -time1.lte(time2); - -// $ExpectType boolean -time1.gt(time2); - -// $ExpectType boolean -time1.gte(time2); - -// $ExpectType Time -time3.toMsg(); - -// ---- Clock ----- -// $ExpectType Clock -const clock = new rclnodejs.Clock(rclnodejs.ClockType.SYSTEM_TIME); - -// $ExpectType ClockType -clock.clockType; - -// $ExpectType Time -clock.now(); - -// ---- ROS Clock ----- - -// ---- Logging ----- -// $ExpectType Logging -const logger = rclnodejs.Logging.getLogger('test_logger'); - -// $ExpectType string -logger.name; - -// $ExpectType LoggingSeverity -logger.loggerEffectiveLevel; - -// $ExpectType void -logger.setLoggerLevel(rclnodejs.Logging.LoggingSeverity.INFO); - -// $ExpectType boolean -logger.debug('test msg'); - -// $ExpectType boolean -logger.info('test msg'); - -// $ExpectType boolean -logger.warn('test msg'); - -// $ExpectType boolean -logger.error('test msg'); - -// $ExpectType boolean -logger.fatal('test msg'); - -// TODO - reinstate the disabled (commented out) test due to -// somewhat false negatives reported by multiple version of typescript -// and undefined rules for how union type ordering - -// // FOXY-ONLY, example_interfaces introduced with foxy release -// // ---- Int8Array ---- -// const i8arr = rclnodejs.require( -// 'example_interfaces.msg.Int8MultiArray' -// ) as rclnodejs.example_interfaces.msg.Int8MultiArray; -// // $ExpectType Int8Array | number[] -// i8arr.data; - -// // ---- Uint8Array ---- -// const u8arr = rclnodejs.require( -// 'example_interfaces.msg.UInt8MultiArray' -// ) as rclnodejs.example_interfaces.msg.UInt8MultiArray; -// // $ExpectType Uint8Array | number[] -// u8arr.data; - -// // ---- Int16Array ---- -// const i16arr = rclnodejs.require( -// 'example_interfaces.msg.Int16MultiArray' -// ) as rclnodejs.example_interfaces.msg.Int16MultiArray; -// // $ExpectType Int16Array | number[] -// i16arr.data; - -// // ---- Uint16Array ---- -// const u16arr = rclnodejs.require( -// 'example_interfaces.msg.UInt16MultiArray' -// ) as rclnodejs.example_interfaces.msg.UInt16MultiArray; -// // $ExpectType Uint16Array | number[] -// u16arr.data; - -// // ---- Int32Array ---- -// const i32arr = rclnodejs.require( -// 'example_interfaces.msg.Int32MultiArray' -// ) as rclnodejs.example_interfaces.msg.Int32MultiArray; -// // $ExpectType Int32Array | number[] -// i32arr.data; - -// // ---- Uint16Array ---- -// const u32arr = rclnodejs.require( -// 'example_interfaces.msg.UInt32MultiArray' -// ) as rclnodejs.example_interfaces.msg.UInt32MultiArray; -// // $ExpectType Uint32Array | number[] -// u32arr.data; - -// // ---- Float32Array ---- -// const f32arr = rclnodejs.require( -// 'example_interfaces.msg.Float32MultiArray' -// ) as rclnodejs.example_interfaces.msg.Float32MultiArray; -// // $ExpectType Float32Array | number[] -// f32arr.data; - -// // ---- Float64Array ---- -// const f64arr = rclnodejs.require( -// 'example_interfaces.msg.Float64MultiArray' -// ) as rclnodejs.example_interfaces.msg.Float64MultiArray; -// // $ExpectType Float64Array | number[] -// f64arr.data; - -// $ExpectType FibonacciConstructor -const Fibonacci = rclnodejs.require('example_interfaces/action/Fibonacci'); - -// ---- ActionClient ----- -// $ExpectType ActionClient<"example_interfaces/action/Fibonacci"> -const actionClient = new rclnodejs.ActionClient( - node, - 'example_interfaces/action/Fibonacci', - 'fibonnaci' -); - -// $ExpectType boolean -client.isServiceServerAvailable(); - -// $ExpectType Promise -actionClient.waitForServer(); - -// $ExpectType void -actionClient.destroy(); - -// $ExpectType Promise> -const goalHandlePromise = actionClient.sendGoal(new Fibonacci.Goal()); - -goalHandlePromise.then((goalHandle) => { - // $ExpectType boolean - goalHandle.accepted; // deprecated - - // $ExpectType UUID - goalHandle.goalId; - - // $ExpectType Time - goalHandle.stamp; - - // $ExpectType number - goalHandle.status; - - // $ExpectType Promise - goalHandle.cancelGoal(); - - // $ExpectType Promise - goalHandle.getResult(); - - // $ExpectType boolean - goalHandle.isAccepted(); - - // $ExpectType boolean - goalHandle.isExecuting(); - - // $ExpectType boolean - goalHandle.isSucceeded(); - - // $ExpectType boolean - goalHandle.isCanceling(); - - // $ExpectType boolean - goalHandle.isCanceled(); - - // $ExpectType boolean - goalHandle.isAborted(); -}); - -// ---- ActionServer ----- -// $ExpectType ActionServer<"example_interfaces/action/Fibonacci"> -const actionServer = new rclnodejs.ActionServer( - node, - 'example_interfaces/action/Fibonacci', - 'fibonnaci', - executeCallback -); - -// $ExpectType void -actionServer.registerHandleAcceptedCallback(); - -// $ExpectType void -actionServer.registerGoalCallback(); - -// $ExpectType void -actionServer.registerCancelCallback(); - -// $ExpectType void -actionServer.registerExecuteCallback(() => new Fibonacci.Result()); - -// $ExpectType void -actionServer.destroy(); - -function executeCallback( - goalHandle: rclnodejs.ServerGoalHandle<'example_interfaces/action/Fibonacci'> -) { - // $ExpectType UUID - goalHandle.goalId; - - // $ExpectType boolean - goalHandle.isActive; - - // $ExpectType boolean - goalHandle.isCancelRequested; - - // $ExpectType Fibonacci_Goal - goalHandle.request; - - // $ExpectType string - goalHandle.status; - - // $ExpectType void - goalHandle.abort(); - - // $ExpectType void - goalHandle.canceled(); - - // $ExpectType void - goalHandle.execute(); - - // $ExpectType void - goalHandle.publishFeedback(new Fibonacci.Feedback()); - - // $ExpectType void - goalHandle.succeed(); - - return new Fibonacci.Result(); -} - -// ---- ActionUuid ----- -// $ExpectType ActionUuid -const actionUuid = new rclnodejs.ActionUuid(); - -// $ExpectType ActionUuid -const actionUuid1 = rclnodejs.ActionUuid.random(); - -// $ExpectType ActionUuid -const actionUuid2 = rclnodejs.ActionUuid.fromBytes(new Uint8Array([21, 31])); - -// $ExpectType string -actionUuid.toString(); - -// $ExpectType Uint8Array -actionUuid.bytes; - -// $ExpectType UUID -actionUuid.toMessage(); - -// $ExpectType UUID -rclnodejs.ActionUuid.randomMessage(); - -// ---- Parameter ----- -// $ExpectType Parameter -const param = rclnodejs.createMessageObject('rcl_interfaces/msg/Parameter'); -param.name = 'integer_param'; -param.value.type = rclnodejs.ParameterType.PARAMETER_INTEGER; -param.value.integer_value = BigInt(123); - -param.name = 'byte_array_param'; -param.value.type = rclnodejs.ParameterType.PARAMETER_BYTE_ARRAY; -param.value.byte_array_value = [1, 2, 3]; diff --git a/test/types/test.ts b/test/types/test.ts deleted file mode 100644 index 92609636..00000000 --- a/test/types/test.ts +++ /dev/null @@ -1,20 +0,0 @@ -/// -import * as rclnodejs from 'rclnodejs'; - -// TODO - reinstate the disabled (commented out) test due to -// somewhat false negatives reported by multiple version of typescript -// and undefined rules for how union type ordering - -// // ---- Uint8Array ---- -// const u8arr = rclnodejs.require( -// 'example_interfaces.msg.UInt8MultiArray' -// ) as rclnodejs.example_interfaces.msg.UInt8MultiArray; -// // $ExpectType Uint8Array | number[] -// u8arr.data; - -// // ---- Uint8Array ---- -// const u8arrx = rclnodejs.require( -// 'std_msgs.msg.UInt8MultiArray' -// ) as rclnodejs.std_msgs.msg.UInt8MultiArray; -// // $ExpectType Uint8Array | number[] -// u8arrx.data; diff --git a/test/types/tsconfig.json b/test/types/tsconfig.json deleted file mode 100644 index 6c4d6052..00000000 --- a/test/types/tsconfig.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "compileOnSave": false, - "compilerOptions": { - "module": "commonjs", - "moduleResolution": "node", - "target": "es6", - /* Strict Type-Checking Options */ - "strict": true, - /* Additional Checks */ - /* next line commented out because we need unused vars for type tests */ - // "noUnusedLocals": true, - "noUnusedParameters": false, - "noImplicitReturns": true, - "noFallthroughCasesInSwitch": true, - "lib": ["es2017"] - } -} \ No newline at end of file diff --git a/test/types/tslint.json b/test/types/tslint.json deleted file mode 100644 index f0b6fec2..00000000 --- a/test/types/tslint.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "dtslint/dtslint.json", - "rules": { - "no-useless-files": false, - "eofline": false, - "no-bad-reference": false, - "no-consecutive-blank-lines": false, - "no-unused-variable": false, - "trim-file": false - } -} \ No newline at end of file