Skip to content

Commit 39fc0b2

Browse files
committed
Make TS happier with year/eraYear
This was originally part of tc39/proposal-temporal#1977 but I removed it because it wasn't high-priority for JS. But it's still needed in this repo so I'm adding it back. Why? TS complains when you assign a maybe-undefined value to a must-not-be-undefined variable. This small runtime change is cleaner than adding a lotta type casts.
1 parent ef8c588 commit 39fc0b2

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/calendar.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,8 +1305,8 @@ const helperHebrew: NonIsoHelperBase = ObjectAssign({}, nonIsoHelperBase, {
13051305
fromLegacyDate = false
13061306
) {
13071307
let { year, eraYear, month, monthCode, day, monthExtra } = calendarDate;
1308-
if (year === undefined) year = eraYear;
1309-
if (eraYear === undefined) eraYear = year;
1308+
if (year === undefined && eraYear !== undefined) year = eraYear;
1309+
if (eraYear === undefined && year !== undefined) eraYear = year;
13101310
if (fromLegacyDate) {
13111311
// In Pre Node-14 V8, DateTimeFormat.formatToParts `month: 'numeric'`
13121312
// output returns the numeric equivalent of `month` as a string, meaning

0 commit comments

Comments
 (0)