@@ -4780,8 +4780,8 @@ export function RoundDuration(
47804780 // First convert time units up to days, if rounding to days or higher units.
47814781 // If rounding relative to a ZonedDateTime, then some days may not be 24h.
47824782 // TS doesn't know that `dayLengthNs` is only used if the unit is day or
4783- // larger. This makes the cast below acceptable .
4784- let dayLengthNs : JSBI = undefined as unknown as JSBI ;
4783+ // larger. We'll cast away `undefined` when it's used lower down below .
4784+ let dayLengthNs : JSBI | undefined ;
47854785 if ( unit === 'year' || unit === 'month' || unit === 'week' || unit === 'day' ) {
47864786 nanoseconds = TotalDurationNanoseconds ( 0 , hours , minutes , seconds , milliseconds , microseconds , nanosecondsParam , 0 ) ;
47874787 let intermediate ;
@@ -4847,9 +4847,12 @@ export function RoundDuration(
48474847 // the duration. This lets us do days-or-larger rounding using BigInt
48484848 // math which reduces precision loss.
48494849 oneYearDays = MathAbs ( oneYearDays ) ;
4850- const divisor = JSBI . multiply ( JSBI . BigInt ( oneYearDays ) , dayLengthNs ) ;
4850+ // dayLengthNs is never undefined if unit is `day` or larger.
4851+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4852+ const divisor = JSBI . multiply ( JSBI . BigInt ( oneYearDays ) , dayLengthNs ! ) ;
48514853 nanoseconds = JSBI . add (
4852- JSBI . add ( JSBI . multiply ( divisor , JSBI . BigInt ( years ) ) , JSBI . multiply ( JSBI . BigInt ( days ) , dayLengthNs ) ) ,
4854+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4855+ JSBI . add ( JSBI . multiply ( divisor , JSBI . BigInt ( years ) ) , JSBI . multiply ( JSBI . BigInt ( days ) , dayLengthNs ! ) ) ,
48534856 nanoseconds
48544857 ) ;
48554858 const rounded = RoundNumberToIncrement (
@@ -4903,9 +4906,12 @@ export function RoundDuration(
49034906 ( { relativeTo, days : oneMonthDays } = MoveRelativeDate ( calendar , relativeTo , oneMonth ) ) ;
49044907 }
49054908 oneMonthDays = MathAbs ( oneMonthDays ) ;
4906- const divisor = JSBI . multiply ( JSBI . BigInt ( oneMonthDays ) , dayLengthNs ) ;
4909+ // dayLengthNs is never undefined if unit is `day` or larger.
4910+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4911+ const divisor = JSBI . multiply ( JSBI . BigInt ( oneMonthDays ) , dayLengthNs ! ) ;
49074912 nanoseconds = JSBI . add (
4908- JSBI . add ( JSBI . multiply ( divisor , JSBI . BigInt ( months ) ) , JSBI . multiply ( JSBI . BigInt ( days ) , dayLengthNs ) ) ,
4913+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4914+ JSBI . add ( JSBI . multiply ( divisor , JSBI . BigInt ( months ) ) , JSBI . multiply ( JSBI . BigInt ( days ) , dayLengthNs ! ) ) ,
49094915 nanoseconds
49104916 ) ;
49114917 const rounded = RoundNumberToIncrement (
@@ -4933,9 +4939,12 @@ export function RoundDuration(
49334939 ( { relativeTo, days : oneWeekDays } = MoveRelativeDate ( calendar , relativeTo , oneWeek ) ) ;
49344940 }
49354941 oneWeekDays = MathAbs ( oneWeekDays ) ;
4936- const divisor = JSBI . multiply ( JSBI . BigInt ( oneWeekDays ) , dayLengthNs ) ;
4942+ // dayLengthNs is never undefined if unit is `day` or larger.
4943+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4944+ const divisor = JSBI . multiply ( JSBI . BigInt ( oneWeekDays ) , dayLengthNs ! ) ;
49374945 nanoseconds = JSBI . add (
4938- JSBI . add ( JSBI . multiply ( divisor , JSBI . BigInt ( weeks ) ) , JSBI . multiply ( JSBI . BigInt ( days ) , dayLengthNs ) ) ,
4946+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4947+ JSBI . add ( JSBI . multiply ( divisor , JSBI . BigInt ( weeks ) ) , JSBI . multiply ( JSBI . BigInt ( days ) , dayLengthNs ! ) ) ,
49394948 nanoseconds
49404949 ) ;
49414950 const rounded = RoundNumberToIncrement (
@@ -4950,7 +4959,9 @@ export function RoundDuration(
49504959 break ;
49514960 }
49524961 case 'day' : {
4953- const divisor = dayLengthNs ;
4962+ // dayLengthNs is never undefined if unit is `day` or larger.
4963+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
4964+ const divisor = dayLengthNs ! ;
49544965 nanoseconds = JSBI . add ( JSBI . multiply ( divisor , JSBI . BigInt ( days ) ) , nanoseconds ) ;
49554966 const rounded = RoundNumberToIncrement (
49564967 nanoseconds ,
0 commit comments