Incorrect Type for ClientGoalHandle.getResult
See original GitHub issueDescription
The type definitions for ClientGoalHandle.getResult
indicates that it returns Promise<ActionResult<T>>
. It actually returns a type
interface ActionResultWithStatus<T> {
status: number,
result: ActionResult<T>
};
- Library Version: 0.20.0
- ROS Version: foxy
- Platform / OS: ubuntu 20.04
Steps To Reproduce
The following does not compile with tsc
although if you cast result
to any
it does and result
satisfies ActionResultWithStatus
as described above.
import * as rclnodejs from 'rclnodejs'
async function main() {
await rclnodejs.init();
const node = new rclnodejs.Node('my_node');
node.spin();
const FollowJointTrajectory = rclnodejs.require('control_msgs/action/FollowJointTrajectory');
const action_server = new rclnodejs.ActionServer(node, 'control_msgs/action/FollowJointTrajectory', '/my_action',
(gh) => {
gh.succeed();
const result = new FollowJointTrajectory.Result();
return result;
}
);
const action_client = new rclnodejs.ActionClient(node, 'control_msgs/action/FollowJointTrajectory', '/my_action');
await action_client.waitForServer();
const goal = new FollowJointTrajectory.Goal();
const gh = await action_client.sendGoal(goal);
const result = await gh.getResult();
console.log('Result: %j', result);
console.log('Result Status: ', result.status);
console.log('Result Result: ', result.result);
node.stop();
}
main();
Expected Behavior
compile without casting result
to any
Actual Behavior
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (1 by maintainers)
Top Results From Across the Web
actionlib::SimpleActionClient< ActionSpec > Class Template ...
Cancel all goals that were stamped at and before the specified time. ResultConstPtr, getResult (). Get the Result of the current goal. SimpleClientGoalState ......
Read more >JSDoc: Source: lib/action/client.js - Robot Web Tools
@param {function|string|object} typeClass - Type of the action. ... throw new TypeError('Invalid argument, must be type of ClientGoalHandle'); ...
Read more >Actions — rclpy 0.6.1 documentation - ROS 2 Docs
The result of the returned Future is set to a ClientGoalHandle when receipt of the goal is acknowledged by an action server. Parameters....
Read more >Issues - rclnodejs - Robot Web Tools - Geeks
Types should support overloaded Node methods. #873 opened 4 months ago by wayneparrott ... Incorrect Type for ClientGoalHandle.getResult.
Read more >Cookie Consent doesnt save and doesnt disappear on Reload ...
<button type="button" data-cc="c-settings" class="cc-link">Let me ... Incorrect Type for ClientGoalHandle.getResult, 10, 2021-10-04, 2022-11-28.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
After a little debugging I’ve found 2 issues:
ClientGoalHandle.status
property is intended to hold the status code (state id) across the goal processing lifecycle. Yet, internally this property is not being updated due to a race condition.await ClientGoalHandle.getResult()
is leaking the internal {status,result} object. It should only return theresult
property. If we make this change then the TS types will correctly reflect the api’s behavior. If we choose to return the {status,result} object we will need to add an additional type declaration, e.g.,<T>ResultWithStatus
and modify the generator logic.Looking at #1 now. Will discuss #2 with @minggangw
#1 - a race condition arises when the action-server is sends a status msg before returning a goal-request-response message. The latter msg cause the action-client to setup internal state for the goalClient. Yet, the preceding status msg depends up on the goalClient state to be established which it isn’t. Thus the status msg is ignored. A similar race condition arises when the goal request is completed.
@minggangw yes the example works correctly. The issue is that the typescript types do not match the value the promise resolves with.