From f6a86de6f4aecc9e1c530a6bc7ac84caffe05bae Mon Sep 17 00:00:00 2001 From: Minggang Wang Date: Tue, 25 Feb 2025 11:19:17 +0800 Subject: [PATCH] [TypeScript] Update .ts files for Time/Timer/Duration --- test/types/main.ts | 19 +++++++++++-------- types/duration.d.ts | 7 +++---- types/time.d.ts | 12 +++--------- types/timer.d.ts | 12 ++++++------ 4 files changed, 23 insertions(+), 27 deletions(-) diff --git a/test/types/main.ts b/test/types/main.ts index 612ed45c..a05f471f 100644 --- a/test/types/main.ts +++ b/test/types/main.ts @@ -326,16 +326,16 @@ const timerCallback = () => {}; // $ExpectType Timer const timer = node.createTimer(BigInt(100000), timerCallback); -// $ExpectType number +// $ExpectType bigint timer.period; // $ExpectType boolean timer.isReady(); -// $ExpectType number +// $ExpectType bigint timer.timeSinceLastCall(); -// $ExpectType number +// $ExpectType bigint timer.timeUntilNextCall(); // $ExpectType boolean @@ -366,9 +366,12 @@ timer.cancel(); // $ExpectType Duration const duration1: rclnodejs.Duration = new rclnodejs.Duration(); -const duration2: rclnodejs.Duration = new rclnodejs.Duration(100, '1000'); +const duration2: rclnodejs.Duration = new rclnodejs.Duration( + BigInt(100), + BigInt(1000) +); -// $ExpectType string | number +// $ExpectType bigint duration1.nanoseconds; // $ExpectType boolean @@ -391,7 +394,7 @@ duration1.gte(duration2); // ---- Time ---- // $ExpectType Time -const time1 = new rclnodejs.Time(100, 100); +const time1 = new rclnodejs.Time(BigInt(100), BigInt(100)); // $ExpectType Time const time2 = rclnodejs.Time.fromMsg({ sec: 0, nanosec: 0 }); @@ -405,10 +408,10 @@ const time3 = rclnodejs.Time.fromMsg( // $ExpectType ClockType time1.clockType; -// $ExpectType string | number +// $ExpectType bigint time1.nanoseconds; -// $ExpectType { seconds: number; nanoseconds: number; } +// $ExpectType { seconds: bigint; nanoseconds: bigint; } time1.secondsAndNanoseconds; // $ExpectType Time diff --git a/types/duration.d.ts b/types/duration.d.ts index 37138153..c77f7c06 100644 --- a/types/duration.d.ts +++ b/types/duration.d.ts @@ -10,15 +10,14 @@ declare module 'rclnodejs' { * @param seconds - The seconds component of the duration, default = 0. * @param nanoseconds - The nanoseconds component of the duration, default = 0. */ - constructor(seconds?: number | string, nanoseconds?: number | string); + constructor(seconds?: bigint, nanoseconds?: bigint); /** * Get the nanosecond component of the Duration. * - * @returns The nanoseconds, if the value is greater than Number.MAX_SAFE_INTEGER (2^53-1), - * will be presented in a string of decimal format. + * @returns The nanoseconds. */ - readonly nanoseconds: number | string; + readonly nanoseconds: bigint; /** * Test if this Duration is equal to another Duration. diff --git a/types/time.d.ts b/types/time.d.ts index 07aa95c9..3bc70cb4 100644 --- a/types/time.d.ts +++ b/types/time.d.ts @@ -14,11 +14,7 @@ declare module 'rclnodejs' { * @param nanoseconds - The nanoseconds component of the time, default = 0. * @param clockType - The clock type, default = Clock.ClockType.SYSTEM_TIME */ - constructor( - seconds?: number | string, - nanoseconds?: number | string, - clockType?: ClockType - ); + constructor(seconds?: bigint, nanoseconds?: bigint, clockType?: ClockType); /** * Get the the clock type of the Time object. @@ -27,15 +23,13 @@ declare module 'rclnodejs' { /** * Get the nanosecond part of the time. - * If the value is greater than Number.MAX_SAFE_INTEGER (2^53-1) it - * will be returned in a string of decimal format. */ - readonly nanoseconds: number | string; + readonly nanoseconds: bigint; /** * Get the time as a plain JavaScript object. */ - readonly secondsAndNanoseconds: { seconds: number; nanoseconds: number }; + readonly secondsAndNanoseconds: { seconds: bigint; nanoseconds: bigint }; /** * Add a duration to this time object. diff --git a/types/timer.d.ts b/types/timer.d.ts index 0c707b57..04f0f880 100644 --- a/types/timer.d.ts +++ b/types/timer.d.ts @@ -4,9 +4,9 @@ declare module 'rclnodejs' { */ interface Timer { /** - * Time between callbacks in milliseconds. + * Time between callbacks in nanoseconds. */ - readonly period: number; + readonly period: bigint; /** * Check if the timer is ready. @@ -35,15 +35,15 @@ declare module 'rclnodejs' { /** * Get the interval since the last call of this timer. * - * @returns The interval value in milliseconds. + * @returns The interval value in nanoseconds. */ - timeSinceLastCall(): number; + timeSinceLastCall(): bigint; /** * Get the interval until the next call will happen. * - * @returns The interval value in milliseconds + * @returns The interval value in nanoseconds */ - timeUntilNextCall(): number; + timeUntilNextCall(): bigint; } }