Skip to content

Commit 4677e79

Browse files
authored
Enable @typescript-eslint/consistent-type-imports (#1040)
This makes sure bundlers (Vite, in our case) know that they can drop the import in the resulting JS if it was only used for type-checking and isn't used at runtime.
1 parent 15fe862 commit 4677e79

24 files changed

+55
-53
lines changed

eslint.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export default defineConfig(
3030
// Plenty of APIs (like mocking APIs in Vitest) require empty functions to be declared.
3131
"@typescript-eslint/no-empty-function": 0,
3232
"prefer-template": 2,
33+
"@typescript-eslint/consistent-type-imports": 2,
3334
},
3435
},
3536
{

src/actionlib/ActionClient.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
* @author Russell Toris - rctoris@wpi.edu
44
*/
55

6-
import Ros from "../core/Ros.js";
6+
import type Ros from "../core/Ros.js";
77
import Topic from "../core/Topic.js";
88
import { EventEmitter } from "eventemitter3";
9-
import { actionlib_msgs } from "../types/actionlib_msgs.js";
10-
import Goal from "./Goal.js";
9+
import type { actionlib_msgs } from "../types/actionlib_msgs.js";
10+
import type Goal from "./Goal.js";
1111

1212
/**
1313
* An actionlib action client.

src/actionlib/ActionListener.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
* @author Russell Toris - rctoris@wpi.edu
55
*/
66

7-
import Ros from "../core/Ros.js";
7+
import type Ros from "../core/Ros.js";
88
import Topic from "../core/Topic.js";
99
import { EventEmitter } from "eventemitter3";
10-
import { actionlib_msgs } from "../types/actionlib_msgs.js";
10+
import type { actionlib_msgs } from "../types/actionlib_msgs.js";
1111

1212
/**
1313
* An actionlib action listener.

src/actionlib/Goal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*/
55

66
import { EventEmitter } from "eventemitter3";
7-
import ActionClient from "./ActionClient";
8-
import { actionlib_msgs } from "../types/actionlib_msgs";
7+
import type ActionClient from "./ActionClient";
8+
import type { actionlib_msgs } from "../types/actionlib_msgs";
99
import { v4 as uuidv4 } from "uuid";
1010

1111
/**

src/actionlib/SimpleActionServer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
* @author Laura Lindzey - lindzey@gmail.com
44
*/
55

6-
import Ros from "../core/Ros.js";
6+
import type Ros from "../core/Ros.js";
77
import Topic from "../core/Topic.js";
88
import { EventEmitter } from "eventemitter3";
9-
import { actionlib_msgs } from "../types/actionlib_msgs.js";
10-
import { std_msgs } from "../types/std_msgs.js";
9+
import type { actionlib_msgs } from "../types/actionlib_msgs.js";
10+
import type { std_msgs } from "../types/std_msgs.js";
1111

1212
/**
1313
* An actionlib action server client.

src/core/Action.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
*/
55

66
import { GoalStatus } from "./GoalStatus.ts";
7+
import type { RosbridgeSendActionGoalMessage } from "../types/protocol.ts";
78
import {
89
isRosbridgeActionFeedbackMessage,
910
isRosbridgeActionResultMessage,
1011
isRosbridgeCancelActionGoalMessage,
1112
isRosbridgeSendActionGoalMessage,
12-
RosbridgeSendActionGoalMessage,
1313
} from "../types/protocol.ts";
14-
import Ros from "./Ros.js";
14+
import type Ros from "./Ros.js";
1515
import { v4 as uuidv4 } from "uuid";
1616

1717
/**

src/core/Param.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* @author Brandon Alexander - baalexander@gmail.com
44
*/
55

6-
import { rosapi } from "../types/rosapi.js";
7-
import Ros from "./Ros.js";
6+
import type { rosapi } from "../types/rosapi.js";
7+
import type Ros from "./Ros.js";
88
import Service from "./Service.js";
99

1010
/**

src/core/Ros.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import socketAdapter from "./SocketAdapter.js";
7+
import type { RosbridgeMessage } from "../types/protocol.js";
78
import {
89
isRosbridgeActionFeedbackMessage,
910
isRosbridgeActionResultMessage,
@@ -13,7 +14,6 @@ import {
1314
isRosbridgeSendActionGoalMessage,
1415
isRosbridgeServiceResponseMessage,
1516
isRosbridgeStatusMessage,
16-
RosbridgeMessage,
1717
} from "../types/protocol.js";
1818

1919
import Topic from "./Topic.js";
@@ -23,7 +23,8 @@ import TFClient from "../tf/TFClient";
2323
import ActionClient from "../actionlib/ActionClient.js";
2424
import SimpleActionServer from "../actionlib/SimpleActionServer.js";
2525
import { EventEmitter } from "eventemitter3";
26-
import { rosapi } from "../types/rosapi.ts";
26+
import type { rosapi } from "../types/rosapi.ts";
27+
import type { WebSocket as WsWebSocket } from "ws";
2728

2829
function isRTCPeerDataChannel(obj: unknown): obj is RTCPeerConnection {
2930
return obj?.constructor.name === "RTCDataChannel";
@@ -47,8 +48,7 @@ export default class Ros extends EventEmitter<
4748
// Any dynamically-named event should correspond to a rosbridge protocol message
4849
} & Record<string, [RosbridgeMessage]>
4950
> {
50-
/** @type {import('./SocketAdapter.js').default | null} */
51-
socket: import("./SocketAdapter.js").default | null = null;
51+
socket: socketAdapter | null = null;
5252
isConnected = false;
5353
transportLibrary: "websocket" | RTCPeerConnection;
5454
transportOptions: {
@@ -90,7 +90,7 @@ export default class Ros extends EventEmitter<
9090
*/
9191
async #createTransport(
9292
url: string,
93-
): Promise<WebSocket | RTCDataChannel | import("ws").WebSocket | null> {
93+
): Promise<WebSocket | RTCDataChannel | WsWebSocket | null> {
9494
if (isRTCPeerDataChannel(this.transportLibrary)) {
9595
const dataChannel = this.transportLibrary.createDataChannel(
9696
url,

src/core/Service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
*/
55

66
import { EventEmitter } from "eventemitter3";
7-
import {
8-
isRosbridgeServiceResponseMessage,
7+
import type {
98
RosbridgeCallServiceMessage,
109
RosbridgeServiceResponseMessage,
1110
} from "../types/protocol.ts";
12-
import Ros from "./Ros.js";
11+
import { isRosbridgeServiceResponseMessage } from "../types/protocol.ts";
12+
import type Ros from "./Ros.js";
1313
import { v4 as uuidv4 } from "uuid";
1414

1515
/**

src/core/SocketAdapter.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import CBOR from "cbor-js";
22
import typedArrayTagger from "../util/cborTypedArrayTags.js";
3+
import type {
4+
RosbridgeFragmentMessage,
5+
RosbridgeMessage,
6+
} from "../types/protocol.js";
37
import {
48
isRosbridgeFragmentMessage,
59
isRosbridgeMessage,
610
isRosbridgePngMessage,
7-
RosbridgeFragmentMessage,
8-
RosbridgeMessage,
911
} from "../types/protocol.js";
1012
import { deserialize } from "bson";
13+
import type { WebSocket as WsWebSocket } from "ws";
1114

1215
export type RequiredSocketInterface = Pick<
13-
WebSocket | RTCDataChannel | import("ws").WebSocket,
16+
WebSocket | RTCDataChannel | WsWebSocket,
1417
| "onmessage"
1518
| "onclose"
1619
| "onerror"

0 commit comments

Comments
 (0)