@@ -4756,8 +4756,8 @@ export function RoundDuration(
47564756 // First convert time units up to days, if rounding to days or higher units.
47574757 // If rounding relative to a ZonedDateTime, then some days may not be 24h.
47584758 // TS doesn't know that `dayLengthNs` is only used if the unit is day or
4759- // larger. This makes the cast below acceptable .
4760- let dayLengthNs : JSBI = undefined as unknown as JSBI ;
4759+ // larger. We'll cast away `undefined` when it's used lower down below .
4760+ let dayLengthNs : JSBI | undefined ;
47614761 if ( unit === 'year' || unit === 'month' || unit === 'week' || unit === 'day' ) {
47624762 nanoseconds = TotalDurationNanoseconds ( 0 , hours , minutes , seconds , milliseconds , microseconds , nanosecondsParam , 0 ) ;
47634763 let intermediate ;
@@ -4823,9 +4823,12 @@ export function RoundDuration(
48234823 // the duration. This lets us do days-or-larger rounding using BigInt
48244824 // math which reduces precision loss.
48254825 oneYearDays = MathAbs ( oneYearDays ) ;
4826- const divisor = JSBI . multiply ( JSBI . BigInt ( oneYearDays ) , dayLengthNs ) ;
4826+ // dayLengthNs is never undefined if unit is `day` or larger.
4827+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4828+ const divisor = JSBI . multiply ( JSBI . BigInt ( oneYearDays ) , dayLengthNs ! ) ;
48274829 nanoseconds = JSBI . add (
4828- JSBI . add ( JSBI . multiply ( divisor , JSBI . BigInt ( years ) ) , JSBI . multiply ( JSBI . BigInt ( days ) , dayLengthNs ) ) ,
4830+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4831+ JSBI . add ( JSBI . multiply ( divisor , JSBI . BigInt ( years ) ) , JSBI . multiply ( JSBI . BigInt ( days ) , dayLengthNs ! ) ) ,
48294832 nanoseconds
48304833 ) ;
48314834 const rounded = RoundNumberToIncrement (
@@ -4879,9 +4882,12 @@ export function RoundDuration(
48794882 ( { relativeTo, days : oneMonthDays } = MoveRelativeDate ( calendar , relativeTo , oneMonth ) ) ;
48804883 }
48814884 oneMonthDays = MathAbs ( oneMonthDays ) ;
4882- const divisor = JSBI . multiply ( JSBI . BigInt ( oneMonthDays ) , dayLengthNs ) ;
4885+ // dayLengthNs is never undefined if unit is `day` or larger.
4886+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4887+ const divisor = JSBI . multiply ( JSBI . BigInt ( oneMonthDays ) , dayLengthNs ! ) ;
48834888 nanoseconds = JSBI . add (
4884- JSBI . add ( JSBI . multiply ( divisor , JSBI . BigInt ( months ) ) , JSBI . multiply ( JSBI . BigInt ( days ) , dayLengthNs ) ) ,
4889+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4890+ JSBI . add ( JSBI . multiply ( divisor , JSBI . BigInt ( months ) ) , JSBI . multiply ( JSBI . BigInt ( days ) , dayLengthNs ! ) ) ,
48854891 nanoseconds
48864892 ) ;
48874893 const rounded = RoundNumberToIncrement (
@@ -4909,9 +4915,12 @@ export function RoundDuration(
49094915 ( { relativeTo, days : oneWeekDays } = MoveRelativeDate ( calendar , relativeTo , oneWeek ) ) ;
49104916 }
49114917 oneWeekDays = MathAbs ( oneWeekDays ) ;
4912- const divisor = JSBI . multiply ( JSBI . BigInt ( oneWeekDays ) , dayLengthNs ) ;
4918+ // dayLengthNs is never undefined if unit is `day` or larger.
4919+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4920+ const divisor = JSBI . multiply ( JSBI . BigInt ( oneWeekDays ) , dayLengthNs ! ) ;
49134921 nanoseconds = JSBI . add (
4914- JSBI . add ( JSBI . multiply ( divisor , JSBI . BigInt ( weeks ) ) , JSBI . multiply ( JSBI . BigInt ( days ) , dayLengthNs ) ) ,
4922+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4923+ JSBI . add ( JSBI . multiply ( divisor , JSBI . BigInt ( weeks ) ) , JSBI . multiply ( JSBI . BigInt ( days ) , dayLengthNs ! ) ) ,
49154924 nanoseconds
49164925 ) ;
49174926 const rounded = RoundNumberToIncrement (
@@ -4926,7 +4935,9 @@ export function RoundDuration(
49264935 break ;
49274936 }
49284937 case 'day' : {
4929- const divisor = dayLengthNs ;
4938+ // dayLengthNs is never undefined if unit is `day` or larger.
4939+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4940+ const divisor = dayLengthNs ! ;
49304941 nanoseconds = JSBI . add ( JSBI . multiply ( divisor , JSBI . BigInt ( days ) ) , nanoseconds ) ;
49314942 const rounded = RoundNumberToIncrement (
49324943 nanoseconds ,
0 commit comments