Skip to content

Commit

Permalink
strictNullChecks/strictPropertyInitialization WIP
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
justingrant committed Dec 13, 2021
1 parent e9c439b commit f7c07fd
Show file tree
Hide file tree
Showing 9 changed files with 610 additions and 413 deletions.
17 changes: 9 additions & 8 deletions index.d.ts
Expand Up @@ -603,8 +603,9 @@ export namespace Temporal {
readonly [Symbol.toStringTag]: 'Temporal.Instant';
}

type EitherYearOrEraAndEraYear = { era: string; eraYear: number } | { year: number };
type EitherMonthCodeOrMonthAndYear = (EitherYearOrEraAndEraYear & { month: number }) | { monthCode: string };
type YearOrEraAndEraYear = { era: string; eraYear: number } | { year: number };
type MonthCodeOrMonthAndYear = (YearOrEraAndEraYear & { month: number }) | { monthCode: string };
type MonthOrMonthCode = { month: number } | { monthCode: string };

export interface CalendarProtocol {
id?: string;
Expand Down Expand Up @@ -648,15 +649,15 @@ export namespace Temporal {
date: Temporal.PlainDate | Temporal.PlainDateTime | Temporal.PlainYearMonth | PlainDateLike | string
): boolean;
dateFromFields(
fields: EitherMonthCodeOrMonthAndYear & { day: number },
fields: YearOrEraAndEraYear & MonthOrMonthCode & { day: number },
options?: AssignmentOptions
): Temporal.PlainDate;
yearMonthFromFields(
fields: EitherYearOrEraAndEraYear & ({ month: number } | { monthCode: string }),
fields: YearOrEraAndEraYear & MonthOrMonthCode,
options?: AssignmentOptions
): Temporal.PlainYearMonth;
monthDayFromFields(
fields: EitherMonthCodeOrMonthAndYear & { day: number },
fields: MonthCodeOrMonthAndYear & { day: number },
options?: AssignmentOptions
): Temporal.PlainMonthDay;
dateAdd(
Expand Down Expand Up @@ -726,15 +727,15 @@ export namespace Temporal {
date: Temporal.PlainDate | Temporal.PlainDateTime | Temporal.PlainYearMonth | PlainDateLike | string
): boolean;
dateFromFields(
fields: EitherMonthCodeOrMonthAndYear & { day: number },
fields: YearOrEraAndEraYear & MonthOrMonthCode & { day: number },
options?: AssignmentOptions
): Temporal.PlainDate;
yearMonthFromFields(
fields: EitherYearOrEraAndEraYear & ({ month: number } | { monthCode: string }),
fields: YearOrEraAndEraYear & MonthOrMonthCode,
options?: AssignmentOptions
): Temporal.PlainYearMonth;
monthDayFromFields(
fields: EitherMonthCodeOrMonthAndYear & { day: number },
fields: MonthCodeOrMonthAndYear & { day: number },
options?: AssignmentOptions
): Temporal.PlainMonthDay;
dateAdd(
Expand Down
612 changes: 360 additions & 252 deletions lib/calendar.ts

Large diffs are not rendered by default.

0 comments on commit f7c07fd

Please sign in to comment.