Skip to content

Commit f7c07fd

Browse files
committed
strictNullChecks/strictPropertyInitialization WIP
This PR focuses on unblocking `strictNullChecks` and `strictPropertyInitialization` in ecmascript.ts and calendar.ts. It's intended as a complement to @jens-ox's work to remove `GetIntrinsic`. This PR: * Enables strictNullChecks: true and strictPropertyInitialization: true in tsconfig.json. * Improves calendar.ts TS types (this was most of the work in this PR) * Removes all unnecessary use of `any` throughout the polyfill * Updates types of ecmascript.ts and fixes a number of type bugs * Ports several proposal-temporal PRs: * tc39/proposal-temporal#1975 - Refactors to align ecmascript.mjs with spec text * tc39/proposal-temporal#1974 - Ensure that Temporal prototypes aren't writable * tc39/proposal-temporal#1976 - Throw RangeError if there's an invalid offset string in ZonedDateTime-representing property bags * tc39/proposal-temporal#1977 - Refactor and fix non-ISO calendars in polyfill * Fixes a few index.d.ts types * Refactors a few types in intl.ts * A handful of trivial type changes in other files (ecmascript.ts and calendar-ts were 95%+ of the work). I'd like to split out the runtime behavior changes (mostly the ported PRs above) into a smaller PR which should make it easier to review changes that can actually break things at runtime. I also need to port tests over from tc39/proposal-temporal#1976. Once those are split out, this PR should be ready to review.
1 parent e9c439b commit f7c07fd

9 files changed

+610
-413
lines changed

index.d.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,9 @@ export namespace Temporal {
603603
readonly [Symbol.toStringTag]: 'Temporal.Instant';
604604
}
605605

606-
type EitherYearOrEraAndEraYear = { era: string; eraYear: number } | { year: number };
607-
type EitherMonthCodeOrMonthAndYear = (EitherYearOrEraAndEraYear & { month: number }) | { monthCode: string };
606+
type YearOrEraAndEraYear = { era: string; eraYear: number } | { year: number };
607+
type MonthCodeOrMonthAndYear = (YearOrEraAndEraYear & { month: number }) | { monthCode: string };
608+
type MonthOrMonthCode = { month: number } | { monthCode: string };
608609

609610
export interface CalendarProtocol {
610611
id?: string;
@@ -648,15 +649,15 @@ export namespace Temporal {
648649
date: Temporal.PlainDate | Temporal.PlainDateTime | Temporal.PlainYearMonth | PlainDateLike | string
649650
): boolean;
650651
dateFromFields(
651-
fields: EitherMonthCodeOrMonthAndYear & { day: number },
652+
fields: YearOrEraAndEraYear & MonthOrMonthCode & { day: number },
652653
options?: AssignmentOptions
653654
): Temporal.PlainDate;
654655
yearMonthFromFields(
655-
fields: EitherYearOrEraAndEraYear & ({ month: number } | { monthCode: string }),
656+
fields: YearOrEraAndEraYear & MonthOrMonthCode,
656657
options?: AssignmentOptions
657658
): Temporal.PlainYearMonth;
658659
monthDayFromFields(
659-
fields: EitherMonthCodeOrMonthAndYear & { day: number },
660+
fields: MonthCodeOrMonthAndYear & { day: number },
660661
options?: AssignmentOptions
661662
): Temporal.PlainMonthDay;
662663
dateAdd(
@@ -726,15 +727,15 @@ export namespace Temporal {
726727
date: Temporal.PlainDate | Temporal.PlainDateTime | Temporal.PlainYearMonth | PlainDateLike | string
727728
): boolean;
728729
dateFromFields(
729-
fields: EitherMonthCodeOrMonthAndYear & { day: number },
730+
fields: YearOrEraAndEraYear & MonthOrMonthCode & { day: number },
730731
options?: AssignmentOptions
731732
): Temporal.PlainDate;
732733
yearMonthFromFields(
733-
fields: EitherYearOrEraAndEraYear & ({ month: number } | { monthCode: string }),
734+
fields: YearOrEraAndEraYear & MonthOrMonthCode,
734735
options?: AssignmentOptions
735736
): Temporal.PlainYearMonth;
736737
monthDayFromFields(
737-
fields: EitherMonthCodeOrMonthAndYear & { day: number },
738+
fields: MonthCodeOrMonthAndYear & { day: number },
738739
options?: AssignmentOptions
739740
): Temporal.PlainMonthDay;
740741
dateAdd(

lib/calendar.ts

Lines changed: 360 additions & 252 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)