Skip to content

Commit 19b5a41

Browse files
authored
Modernize tsconfig.json for Node.js module resolution (#1528)
- Switch `module` and `moduleResolution` to `nodenext` to align with modern Node.js library publishing and ES module resolution semantics. - Bump `target` and `lib` to `es2022`. The project's existing `engines` floor (`node >= 20.20.2`) guarantees full ES2022 runtime support, so targeting es2022 is safe and lets type-checking reflect modern language features instead of nodenext's floating `target: esnext`. - Add `"types": ["node"]` so raw `tsc --noEmit` resolves Node globals (Buffer, setTimeout, child_process, events, AbortSignal) without relying on tsd's implicit @types/node injection. - Refactor a top-level `await` in test/types/index.test-d.ts into an async IIFE, since nodenext classifies the file as CommonJS where top-level await is illegal. - Remove stale boilerplate section-label comments (`Strict Type-Checking Options`, `Additional Checks`) carried over from the original generated tsconfig template. Fix: #1527
1 parent fce926b commit 19b5a41

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

test/types/index.test-d.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -414,12 +414,15 @@ expectType<void>(timer.clearOnResetCallback());
414414
expectType<rclnodejs.TimerInfo>(timer.callTimerWithInfo());
415415

416416
// ---- Rate ----
417-
const rate = await node.createRate(1);
418-
expectType<rclnodejs.Rate>(rate);
419-
expectType<number>(rate.frequency);
420-
expectType<boolean>(rate.isCanceled());
421-
expectType<Promise<void>>(rate.sleep());
422-
expectType<void>(rate.cancel());
417+
expectType<Promise<rclnodejs.Rate>>(node.createRate(1));
418+
void (async () => {
419+
const rate = await node.createRate(1);
420+
expectType<rclnodejs.Rate>(rate);
421+
expectType<number>(rate.frequency);
422+
expectType<boolean>(rate.isCanceled());
423+
expectType<Promise<void>>(rate.sleep());
424+
expectType<void>(rate.cancel());
425+
})();
423426

424427
// ---- Duration ----
425428
const duration1 = new rclnodejs.Duration();

tsconfig.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
{
22
"compilerOptions": {
3-
"module": "commonjs",
4-
"moduleResolution": "node",
5-
"target": "es2020",
6-
/* Strict Type-Checking Options */
3+
"module": "nodenext",
4+
"moduleResolution": "nodenext",
5+
"target": "es2022",
76
"strict": true,
8-
/* Additional Checks */
97
/* next line commented out because we need unused vars for type tests */
108
// "noUnusedLocals": true,
119
"noUnusedParameters": true,
1210
"noImplicitReturns": true,
1311
"noFallthroughCasesInSwitch": true,
14-
"lib": ["es2020"]
12+
"lib": ["es2022"],
13+
"types": ["node"]
1514
},
1615
"include": [
1716
"types/**/*"

0 commit comments

Comments
 (0)