Skip to content

Fix inconsistent typing of duration properties #1265

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: 6.x
Choose a base branch
from

Conversation

MaxAake
Copy link
Contributor

@MaxAake MaxAake commented Mar 21, 2025

When creating a Duration the seconds and nanoseconds will be converted to Integers, no matter if provided with Integers, Numbers, or BigInts. This is awkward and requires special handling by users

@MaxAake MaxAake changed the base branch from 5.0 to 6.x April 7, 2025 07:40
@MaxAake MaxAake changed the base branch from 6.x to 5.0 April 7, 2025 07:46
@MaxAake MaxAake changed the base branch from 5.0 to 6.x May 14, 2025 12:57
@MaxAake MaxAake changed the base branch from 6.x to 5.0 May 14, 2025 12:59
@MaxAake MaxAake changed the base branch from 5.0 to 6.x May 20, 2025 06:47
@MaxAake MaxAake force-pushed the fix-integer-conversion-with-configs branch from 967c612 to f433d5c Compare May 30, 2025 06:38
@@ -79,6 +79,14 @@ export class Duration<T extends NumberOrInteger = Integer> {
* @type {NumberOrInteger}
*/
this.nanoseconds = util.normalizeNanosecondsForDuration(nanoseconds) as T
if (typeof this.months === 'number' && isInt(this.nanoseconds) && isInt(this.seconds)) {
Copy link
Member

@robsdedude robsdedude Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if Duration is constructed with Duration(someNumber, someInteger, someBigint). I mean it's really ugly and the types state that this is not supported. But

  1. In JS (not TS), nothing is strongly typed
  2. This if is already covering the use-case of mixing different number types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not the biggest issue, since the packer would handle that just fine, but there's always a change that a user does something odd and creates a duration object for their own use somewhere. I'm making a change so that the normalized seconds and nanos will keep the same type as the unnormalized values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants