Skip to content

Commit 4bc27d7

Browse files
authored
Ban function binding (#1076)
* Ban function binding * Fix missing generic type
1 parent 98fdad9 commit 4bc27d7

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

eslint.config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ export default defineConfig(
3131
"@typescript-eslint/no-empty-function": 0,
3232
"prefer-template": 2,
3333
"@typescript-eslint/consistent-type-imports": 2,
34+
"no-restricted-syntax": [
35+
"error",
36+
{
37+
selector: "CallExpression[callee.property.name='bind']",
38+
message:
39+
"Prefer arrow functions over invoking Function.prototype.bind",
40+
},
41+
],
3442
},
3543
},
3644
{

src/core/Action.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ export default class Action<
125125
this.#actionCallback = actionCallback;
126126
this.#cancelCallback = cancelCallback;
127127
this.ros.on(this.name, (msg) => {
128-
if (isRosbridgeSendActionGoalMessage(msg)) {
129-
this.#executeAction.bind(this);
128+
if (isRosbridgeSendActionGoalMessage<TGoal>(msg)) {
129+
this.#executeAction(msg);
130130
} else {
131131
throw new Error(
132132
"Received unrelated message on Action server event stream!",

src/types/protocol.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,9 @@ export interface RosbridgeSendActionGoalMessage<TArgs = unknown>
260260
compression?: string;
261261
}
262262

263-
export function isRosbridgeSendActionGoalMessage(
263+
export function isRosbridgeSendActionGoalMessage<TArgs = unknown>(
264264
message: RosbridgeMessageBase,
265-
): message is RosbridgeSendActionGoalMessage {
265+
): message is RosbridgeSendActionGoalMessage<TArgs> {
266266
return message.op === "send_action_goal";
267267
}
268268

0 commit comments

Comments
 (0)