-
Notifications
You must be signed in to change notification settings - Fork 151
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
base: 6.x
Are you sure you want to change the base?
Conversation
967c612
to
f433d5c
Compare
packages/core/src/temporal-types.ts
Outdated
@@ -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)) { |
There was a problem hiding this comment.
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
- In JS (not TS), nothing is strongly typed
- This if is already covering the use-case of mixing different number types.
There was a problem hiding this comment.
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.
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