Skip to content

Commit 7cf1b4a

Browse files
authored
[TypeScript] Update .ts files for Time/Timer/Duration (#1042)
This patch updates the `.d.ts` files according to the following PRs: 1. Change timer period to type of bigint in nanoseconds #1038 2. Leverage BigInt for Time/Duration #1039 Fix: #1041
1 parent 1412425 commit 7cf1b4a

File tree

4 files changed

+23
-27
lines changed

4 files changed

+23
-27
lines changed

test/types/main.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -326,16 +326,16 @@ const timerCallback = () => {};
326326
// $ExpectType Timer
327327
const timer = node.createTimer(BigInt(100000), timerCallback);
328328

329-
// $ExpectType number
329+
// $ExpectType bigint
330330
timer.period;
331331

332332
// $ExpectType boolean
333333
timer.isReady();
334334

335-
// $ExpectType number
335+
// $ExpectType bigint
336336
timer.timeSinceLastCall();
337337

338-
// $ExpectType number
338+
// $ExpectType bigint
339339
timer.timeUntilNextCall();
340340

341341
// $ExpectType boolean
@@ -366,9 +366,12 @@ timer.cancel();
366366
// $ExpectType Duration
367367
const duration1: rclnodejs.Duration = new rclnodejs.Duration();
368368

369-
const duration2: rclnodejs.Duration = new rclnodejs.Duration(100, '1000');
369+
const duration2: rclnodejs.Duration = new rclnodejs.Duration(
370+
BigInt(100),
371+
BigInt(1000)
372+
);
370373

371-
// $ExpectType string | number
374+
// $ExpectType bigint
372375
duration1.nanoseconds;
373376

374377
// $ExpectType boolean
@@ -391,7 +394,7 @@ duration1.gte(duration2);
391394

392395
// ---- Time ----
393396
// $ExpectType Time
394-
const time1 = new rclnodejs.Time(100, 100);
397+
const time1 = new rclnodejs.Time(BigInt(100), BigInt(100));
395398

396399
// $ExpectType Time
397400
const time2 = rclnodejs.Time.fromMsg({ sec: 0, nanosec: 0 });
@@ -405,10 +408,10 @@ const time3 = rclnodejs.Time.fromMsg(
405408
// $ExpectType ClockType
406409
time1.clockType;
407410

408-
// $ExpectType string | number
411+
// $ExpectType bigint
409412
time1.nanoseconds;
410413

411-
// $ExpectType { seconds: number; nanoseconds: number; }
414+
// $ExpectType { seconds: bigint; nanoseconds: bigint; }
412415
time1.secondsAndNanoseconds;
413416

414417
// $ExpectType Time

types/duration.d.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ declare module 'rclnodejs' {
1010
* @param seconds - The seconds component of the duration, default = 0.
1111
* @param nanoseconds - The nanoseconds component of the duration, default = 0.
1212
*/
13-
constructor(seconds?: number | string, nanoseconds?: number | string);
13+
constructor(seconds?: bigint, nanoseconds?: bigint);
1414

1515
/**
1616
* Get the nanosecond component of the Duration.
1717
*
18-
* @returns The nanoseconds, if the value is greater than Number.MAX_SAFE_INTEGER (2^53-1),
19-
* will be presented in a string of decimal format.
18+
* @returns The nanoseconds.
2019
*/
21-
readonly nanoseconds: number | string;
20+
readonly nanoseconds: bigint;
2221

2322
/**
2423
* Test if this Duration is equal to another Duration.

types/time.d.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ declare module 'rclnodejs' {
1414
* @param nanoseconds - The nanoseconds component of the time, default = 0.
1515
* @param clockType - The clock type, default = Clock.ClockType.SYSTEM_TIME
1616
*/
17-
constructor(
18-
seconds?: number | string,
19-
nanoseconds?: number | string,
20-
clockType?: ClockType
21-
);
17+
constructor(seconds?: bigint, nanoseconds?: bigint, clockType?: ClockType);
2218

2319
/**
2420
* Get the the clock type of the Time object.
@@ -27,15 +23,13 @@ declare module 'rclnodejs' {
2723

2824
/**
2925
* Get the nanosecond part of the time.
30-
* If the value is greater than Number.MAX_SAFE_INTEGER (2^53-1) it
31-
* will be returned in a string of decimal format.
3226
*/
33-
readonly nanoseconds: number | string;
27+
readonly nanoseconds: bigint;
3428

3529
/**
3630
* Get the time as a plain JavaScript object.
3731
*/
38-
readonly secondsAndNanoseconds: { seconds: number; nanoseconds: number };
32+
readonly secondsAndNanoseconds: { seconds: bigint; nanoseconds: bigint };
3933

4034
/**
4135
* Add a duration to this time object.

types/timer.d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ declare module 'rclnodejs' {
44
*/
55
interface Timer {
66
/**
7-
* Time between callbacks in milliseconds.
7+
* Time between callbacks in nanoseconds.
88
*/
9-
readonly period: number;
9+
readonly period: bigint;
1010

1111
/**
1212
* Check if the timer is ready.
@@ -35,15 +35,15 @@ declare module 'rclnodejs' {
3535
/**
3636
* Get the interval since the last call of this timer.
3737
*
38-
* @returns The interval value in milliseconds.
38+
* @returns The interval value in nanoseconds.
3939
*/
40-
timeSinceLastCall(): number;
40+
timeSinceLastCall(): bigint;
4141

4242
/**
4343
* Get the interval until the next call will happen.
4444
*
45-
* @returns The interval value in milliseconds
45+
* @returns The interval value in nanoseconds
4646
*/
47-
timeUntilNextCall(): number;
47+
timeUntilNextCall(): bigint;
4848
}
4949
}

0 commit comments

Comments
 (0)