Skip to content

Commit 1420df7

Browse files
authored
Simplify TypeScript config (#1054)
* Simplify TypeScript config * Fix things that were borked due to separate tsconfigs
1 parent a70c501 commit 1420df7

File tree

10 files changed

+137
-121
lines changed

10 files changed

+137
-121
lines changed

test/SocketAdapter.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe("SocketAdapter fragment handling", () => {
3737
client.isConnected = false;
3838
client.emit("close", event);
3939
},
40-
onError: (event: ErrorEvent) => {
40+
onError: (event: ErrorEvent | RTCErrorEvent) => {
4141
client.emit("error", String(event.error));
4242
},
4343
onMessage: (message: RosbridgeMessage) => {

test/examples/fibonacci.example.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as ROSLIB from "../../src/RosLib.js";
33

44
// Noetic is the only version of ROS 1 we support, so we skip based on distro name
55
// instead of adding extra plumbing for ROS_VERSION.
6-
describe.skipIf(process.env.ROS_DISTRO !== "noetic")(
6+
describe.skipIf(process.env["ROS_DISTRO"] !== "noetic")(
77
"ROS 1 Fibonacci Example",
88
function () {
99
it(

test/examples/params.example.ts

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { describe, it, expect, vi } from "vitest";
22
import * as ROSLIB from "../../src/RosLib.js";
33

44
const PARAM_NAME =
5-
process.env.ROS_DISTRO === "noetic"
5+
process.env["ROS_DISTRO"] === "noetic"
66
? "/test/foo"
77
: // Is it crazy to muck around with use_sim_time here? I feel like it shouldn't matter..
88
"/add_two_ints_server:use_sim_time";
@@ -50,26 +50,32 @@ describe("Param setting", function () {
5050

5151
// Known issue with getting params being able to hang in Humble because it had no timeout.
5252
// This doesn't even work with `ros2 param list` at the CLI in our test environment :(
53-
it.skipIf(process.env.ROS_DISTRO === "humble")("ros.getParams", async () => {
54-
const callback = vi.fn();
55-
ros.getParams(callback);
56-
await vi.waitFor(() => {
57-
expect(callback).toHaveBeenCalledOnce();
58-
expect(callback.mock.calls[0][0]).to.include(PARAM_NAME);
59-
});
60-
});
53+
it.skipIf(process.env["ROS_DISTRO"] === "humble")(
54+
"ros.getParams",
55+
async () => {
56+
const callback = vi.fn();
57+
ros.getParams(callback);
58+
await vi.waitFor(() => {
59+
expect(callback).toHaveBeenCalledOnce();
60+
expect(callback.mock.calls[0][0]).to.include(PARAM_NAME);
61+
});
62+
},
63+
);
6164

6265
// In ROS 2 we can't forcibly un-declare someone else's parameter
63-
it.skipIf(process.env.ROS_DISTRO !== "noetic")("Param.delete", async () => {
64-
const callback = vi.fn();
65-
param.delete(callback);
66-
await vi.waitFor(() => {
67-
expect(callback).toHaveBeenCalled();
68-
});
69-
const getParamsCallback = vi.fn();
70-
ros.getParams(getParamsCallback);
71-
await vi.waitFor(() =>
72-
expect(getParamsCallback.mock.calls[0][0]).to.not.include(PARAM_NAME),
73-
);
74-
});
66+
it.skipIf(process.env["ROS_DISTRO"] !== "noetic")(
67+
"Param.delete",
68+
async () => {
69+
const callback = vi.fn();
70+
param.delete(callback);
71+
await vi.waitFor(() => {
72+
expect(callback).toHaveBeenCalled();
73+
});
74+
const getParamsCallback = vi.fn();
75+
ros.getParams(getParamsCallback);
76+
await vi.waitFor(() =>
77+
expect(getParamsCallback.mock.calls[0][0]).to.not.include(PARAM_NAME),
78+
);
79+
},
80+
);
7581
});

test/examples/tf.example.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as ROSLIB from "../../src/RosLib.js";
33

44
// Noetic is the only version of ROS 1 we support, so we skip based on distro name
55
// instead of adding extra plumbing for ROS_VERSION.
6-
describe.skipIf(process.env.ROS_DISTRO !== "noetic")(
6+
describe.skipIf(process.env["ROS_DISTRO"] !== "noetic")(
77
"ROS 1 TF2 Republisher Example",
88
function () {
99
it("tf republisher", () =>

test/examples/tf_service.example.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as ROSLIB from "../../src/RosLib.js";
33

44
// Noetic is the only version of ROS 1 we support, so we skip based on distro name
55
// instead of adding extra plumbing for ROS_VERSION.
6-
describe.skipIf(process.env.ROS_DISTRO !== "noetic")(
6+
describe.skipIf(process.env["ROS_DISTRO"] !== "noetic")(
77
"ROS 1 TF2 Republisher Service Example",
88
function () {
99
it("tf republisher", () =>

test/setup/ros-backend.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const docker = new Docker();
1818
*/
1919
function getRosDistro() {
2020
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- this might be an empty string, not undefined.
21-
return process.env.ROS_DISTRO || "noetic";
21+
return process.env["ROS_DISTRO"] || "noetic";
2222
}
2323

2424
async function waitForRosConnection(ros: Ros, timeout = 5000) {

test/urdf.test.ts

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -88,54 +88,70 @@ describe("URDF", function () {
8888
});
8989

9090
// Check all the visual elements
91-
expect(urdfModel.links.link1.visuals.length).to.equal(1);
92-
if (!(urdfModel.links.link1.visuals[0]?.geometry instanceof UrdfSphere)) {
91+
expect(urdfModel.links["link1"].visuals.length).to.equal(1);
92+
if (
93+
!(urdfModel.links["link1"].visuals[0]?.geometry instanceof UrdfSphere)
94+
) {
9395
throw new Error("Expected geometry to be an instance of UrdfSphere");
9496
}
95-
expect(urdfModel.links.link1.visuals[0]?.geometry?.radius).to.equal(1.0);
96-
if (!(urdfModel.links.link2.visuals[0]?.geometry instanceof UrdfBox)) {
97+
expect(urdfModel.links["link1"].visuals[0]?.geometry?.radius).to.equal(
98+
1.0,
99+
);
100+
if (!(urdfModel.links["link2"].visuals[0]?.geometry instanceof UrdfBox)) {
97101
throw new Error("Expected geometry to be an instance of UrdfBox");
98102
}
99-
expect(urdfModel.links.link2.visuals[0]?.geometry?.dimension?.x).to.equal(
100-
0.5,
101-
);
102-
expect(urdfModel.links.link2.visuals[0]?.geometry?.dimension?.y).to.equal(
103-
0.5,
104-
);
105-
expect(urdfModel.links.link2.visuals[0]?.geometry?.dimension?.z).to.equal(
106-
0.5,
107-
);
103+
expect(
104+
urdfModel.links["link2"].visuals[0]?.geometry?.dimension?.x,
105+
).to.equal(0.5);
106+
expect(
107+
urdfModel.links["link2"].visuals[0]?.geometry?.dimension?.y,
108+
).to.equal(0.5);
109+
expect(
110+
urdfModel.links["link2"].visuals[0]?.geometry?.dimension?.z,
111+
).to.equal(0.5);
108112
if (
109-
!(urdfModel.links.link3.visuals[0]?.geometry instanceof UrdfCylinder)
113+
!(urdfModel.links["link3"].visuals[0]?.geometry instanceof UrdfCylinder)
110114
) {
111115
throw new Error("Expected geometry to be an instance of UrdfCylinder");
112116
}
113-
expect(urdfModel.links.link3.visuals[0]?.geometry?.length).to.equal(2.0);
114-
expect(urdfModel.links.link3.visuals[0]?.geometry?.radius).to.equal(0.2);
117+
expect(urdfModel.links["link3"].visuals[0]?.geometry?.length).to.equal(
118+
2.0,
119+
);
120+
expect(urdfModel.links["link3"].visuals[0]?.geometry?.radius).to.equal(
121+
0.2,
122+
);
115123

116-
expect(urdfModel.links.link4.visuals.length).to.equal(1);
117-
expect(urdfModel.links.link4.visuals[0]?.material?.name).to.equal("red");
118-
expect(urdfModel.links.link4.visuals[0]?.material?.color?.r).to.equal(
124+
expect(urdfModel.links["link4"].visuals.length).to.equal(1);
125+
expect(urdfModel.links["link4"].visuals[0]?.material?.name).to.equal(
126+
"red",
127+
);
128+
expect(urdfModel.links["link4"].visuals[0]?.material?.color?.r).to.equal(
119129
1.0,
120130
);
121-
expect(urdfModel.links.link4.visuals[0]?.material?.color?.g).to.equal(0);
122-
expect(urdfModel.links.link4.visuals[0]?.material?.color?.b).to.equal(0);
123-
expect(urdfModel.links.link4.visuals[0]?.material?.color?.a).to.equal(
131+
expect(urdfModel.links["link4"].visuals[0]?.material?.color?.g).to.equal(
132+
0,
133+
);
134+
expect(urdfModel.links["link4"].visuals[0]?.material?.color?.b).to.equal(
135+
0,
136+
);
137+
expect(urdfModel.links["link4"].visuals[0]?.material?.color?.a).to.equal(
124138
1.0,
125139
);
126140

127-
expect(urdfModel.links.link5.visuals.length).to.equal(2);
128-
expect(urdfModel.links.link5.visuals[0]?.material?.name).to.equal("blue");
129-
expect(urdfModel.links.link5.visuals[0]?.material?.color?.r).to.equal(
141+
expect(urdfModel.links["link5"].visuals.length).to.equal(2);
142+
expect(urdfModel.links["link5"].visuals[0]?.material?.name).to.equal(
143+
"blue",
144+
);
145+
expect(urdfModel.links["link5"].visuals[0]?.material?.color?.r).to.equal(
130146
0.0,
131147
);
132-
expect(urdfModel.links.link5.visuals[0]?.material?.color?.g).to.equal(
148+
expect(urdfModel.links["link5"].visuals[0]?.material?.color?.g).to.equal(
133149
0.0,
134150
);
135-
expect(urdfModel.links.link5.visuals[0]?.material?.color?.b).to.equal(
151+
expect(urdfModel.links["link5"].visuals[0]?.material?.color?.b).to.equal(
136152
1.0,
137153
);
138-
expect(urdfModel.links.link5.visuals[0]?.material?.color?.a).to.equal(
154+
expect(urdfModel.links["link5"].visuals[0]?.material?.color?.a).to.equal(
139155
1.0,
140156
);
141157
});

tsconfig.build.json

Lines changed: 0 additions & 56 deletions
This file was deleted.

tsconfig.json

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,61 @@
11
{
2-
"extends": "./tsconfig.build.json",
32
"compilerOptions": {
4-
"noEmit": true
3+
"noEmit": true,
4+
/* Lib Options */
5+
"target": "es6" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
6+
"lib": [
7+
"es2022",
8+
"DOM",
9+
"DOM.Iterable"
10+
] /* Specify library files to be included in the compilation. */,
11+
"module": "esnext" /* Specify what module code is generated. */,
12+
"moduleResolution": "bundler",
13+
14+
/* JavaScript Support */
15+
"allowJs": false /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */,
16+
"checkJs": false /* Enable error reporting in type-checked JavaScript files. */,
17+
18+
/* Build Options */
19+
"rootDir": "." /* Specify the root folder within your source files. */,
20+
"outDir": "./dist" /* Specify an output folder for all emitted files. */,
21+
"incremental": true /* Enable incremental compilation */,
22+
"tsBuildInfoFile": "./node_modules/.cache/typescript/tsbuildinfo" /* Specify the folder for .tsbuildinfo incremental compilation files. */,
23+
"declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
24+
"skipLibCheck": true /* Skip type checking all .d.ts files. */,
25+
"allowImportingTsExtensions": true,
26+
27+
/* Module Options */
28+
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
29+
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
30+
"isolatedModules": true /* Ensure that each file can be safely transpiled without relying on other imports. */,
31+
32+
/* Strict Type-Checking Options */
33+
/* Gradually enable more of these until we can enable strict mode. */
34+
"strict": false /* Enable all strict type-checking options. */,
35+
/* Rules enabled so far */
36+
"allowUnreachableCode": false /* Disable error reporting for unreachable code. */,
37+
"allowUnusedLabels": false /* Disable error reporting for unused labels. */,
38+
"alwaysStrict": true /* Ensure 'use strict' is always emitted. */,
39+
"noFallthroughCasesInSwitch": true /* Enable error reporting for fallthrough cases in switch statements */,
40+
"strictNullChecks": true /* When type checking, take into account `null` and `undefined`. */,
41+
"noImplicitReturns": true /* Enable error reporting for codepaths that do not explicitly return in a function. */,
42+
"noImplicitThis": true /* Enable error reporting when `this` is given the type `any`. */,
43+
"noPropertyAccessFromIndexSignature": true /* Enforces using indexed accessors for keys declared using an indexed type */,
44+
"noUnusedLocals": true /* Enable error reporting when a local variable isn't read. */,
45+
"noUnusedParameters": true /* Raise an error when a function parameter isn't read */,
46+
"strictBindCallApply": true /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */,
47+
"strictBuiltinIteratorReturn": true /* Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. */,
48+
"useUnknownInCatchVariables": true /* Default catch clause variables as `unknown` instead of `any`. */,
49+
"strictFunctionTypes": true /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */,
50+
"strictPropertyInitialization": true /* Check for class properties that are declared but not set in the constructor. */,
51+
"noImplicitOverride": true /* Ensure overriding members in derived classes are marked with an override modifier. */,
52+
53+
/* Rules to be enabled */
54+
"exactOptionalPropertyTypes": false /* Differentiate between undefined and not present when type checking */,
55+
"noImplicitAny": false /* Enable error reporting for expressions and declarations with an implied 'any' type. */,
56+
"noUncheckedIndexedAccess": false /* Add `undefined` to a type when accessed using an index. */,
57+
58+
"types": ["@types/node"]
559
},
6-
"include": [
7-
"vite.config.ts",
8-
"./src",
9-
"./test",
10-
"eslint.config.ts",
11-
"examples"
12-
]
60+
"exclude": ["docs"]
1361
}

vite.config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import checker from "vite-plugin-checker";
66
export default defineConfig({
77
plugins: [
88
dts({
9-
tsconfigPath: "tsconfig.build.json",
9+
tsconfigPath: "tsconfig.json",
1010
insertTypesEntry: true,
11+
// Only generate types for our actual source code, obv
12+
include: ["src"],
1113
}),
1214
checker({
1315
typescript: {
14-
tsconfigPath: "./tsconfig.build.json",
16+
tsconfigPath: "./tsconfig.json",
1517
},
1618
eslint: {
1719
lintCommand: "eslint .",

0 commit comments

Comments
 (0)