Skip to content

Add types to ecmascript.ts #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 11, 2021

Conversation

justingrant
Copy link
Contributor

@justingrant justingrant commented Oct 4, 2021

Make ecmascript.ts type-safe:

  • Improves types for slots and intrinsics
  • ecmascript.ts now has types throughout and compiles with noImplicitAny
  • Fixes BigInt errors in a few places to fix compiler errors and test failures. Will be replaced by James's work on JSBI.
  • Found and fixed a few index.d.ts bugs in the public types.
  • Overhauled how plural units are handled in TS types.
  • Some initial work in calendar.ts, but I paused that while James does work on that file.
  • Otherwise, only a few few changes outside ecmascript.ts that were required to fix compiler errors.
  • A new internal types file for non-public shared types.

BTW, this is part of a larger roadmap. Here's the tentative plan:

@justingrant justingrant changed the title DO NOT MERGE: Add types to ecmascript.ts DO NOT MERGE: WIP: Add types to ecmascript.ts Oct 5, 2021
@justingrant justingrant force-pushed the function-types branch 12 times, most recently from 5aaf364 to 73fb640 Compare October 7, 2021 06:59
@justingrant justingrant changed the title DO NOT MERGE: WIP: Add types to ecmascript.ts DO NOT MERGE: Add types to ecmascript.ts Oct 7, 2021
@justingrant justingrant force-pushed the function-types branch 3 times, most recently from eef0d7e to 98893f3 Compare October 7, 2021 07:45
@justingrant justingrant force-pushed the function-types branch 4 times, most recently from 40a9ed1 to f8a4a57 Compare October 7, 2021 20:28
@justingrant justingrant changed the title DO NOT MERGE: Add types to ecmascript.ts Add types to ecmascript.ts Oct 7, 2021
@justingrant justingrant marked this pull request as ready for review October 7, 2021 20:51
@justingrant
Copy link
Contributor Author

Not sure why Test262 shows as failed given that the output doesn't report any failures. Trying to re-run.

@justingrant
Copy link
Contributor Author

Hmmm, looks like Test262 tests aren't actually emitting output into the GH actions log. There was a local failure but I don't see its details in CI. I'll fix the failure but seems like something isn't quite right with our CI setup.

Copy link
Contributor

@12wrigja 12wrigja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly just questions for my own understanding.

Copy link
Contributor Author

@justingrant justingrant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reviewing so many changes! I think I've either resolved all the issues you found, or want to defer them until later.

I'll commit the final changes over the weekend and if I don't hear complaints from @ptomato then I'll go ahead and merge because I have a follow-up PR ready to add parameter and return types to all other methods. This includes cleaning up the Parameters stuff you commented about. If there are remaining issues from this PR to deal with, we can resolve them in the next one since there's a lot of overlap.

BTW, adding types to other files found a few bugs in the public types. Was a useful exercise.

fallback: Allowed | 'auto',
disallowedStrings: ReadonlyArray<Disallowed> = [],
autoValue?: IfAuto
): IfAuto extends undefined ? Allowed | 'auto' : Allowed {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I didn't figure out a way in the compiler to validate that Allowed doesn't overlap with Disallowed. Also, agreed on the overloads, because once I typed all the usage of this function then I learned that IfAuto didn't actually work. I'll push a commit with some edits. PTAL.

justingrant added a commit to justingrant/temporal-polyfill that referenced this pull request Oct 10, 2021
This commit continues where js-temporal#74 left off by adding parameter and return
types to the rest of (non-ecmascript.ts) Temporal source files.

Also, it turns on --noImplicitAny.  Getting this working in calendar.ts
will probably require more work than I want to take on in this PR, so I
did an initial pass on obvious types and assigned a lot of `any` for the
rest. Will defnitely need a follow up to improve calendar.ts.

Other than that one file, this should be pretty solid.

One thing I need to figure out is why tests won't work. I think it's
caused by importing Intl fom `..` (to pick up the public types) instead
of importing it from intl.ts directly.  The fix is probably in
resolve.source.mjs but I could use help to figure this out.
justingrant added a commit to justingrant/temporal-polyfill that referenced this pull request Oct 10, 2021
This commit continues where js-temporal#74 left off by adding parameter and return
types to the rest of (non-ecmascript.ts) Temporal source files.

Also, it turns on --noImplicitAny.  The worst `any` offender is
calendar.ts, and fully declaring all its types is more work than
I want to take on in this PR, so I did an initial pass on obvious
types and assigned a lot of `any` for the rest. Will defnitely
need a follow up to improve calendar.ts.

Other than that one file, this commit essentially removes `any`
(implicit or otherwise) from the polyfill, with only a few exceptions
for truly generic code or testing propeties on `globalThis`.

There's still lots of TS work remaining (e.g. strictNullChecks,
strictPropertyInitialization, and cleaning up calendar.ts), but at least
we'll now have valid types on all functions.

I didn't find any runtime errors as a result of this work (good!) but I
did find quite a few problems with the public types in index.d.ts, and
this commit fixes those too.
justingrant added a commit to justingrant/temporal-polyfill that referenced this pull request Oct 10, 2021
This commit continues where js-temporal#74 left off by adding parameter and return
types to the rest of (non-ecmascript.ts) Temporal source files.

Also, it turns on --noImplicitAny.  The worst `any` offender is
calendar.ts, and fully declaring all its types is more work than
I want to take on in this PR, so I did an initial pass on obvious
types and assigned a lot of `any` for the rest. Will defnitely
need a follow up to improve calendar.ts.

Other than that one file, this commit essentially removes `any`
(implicit or otherwise) from the polyfill, with only a few exceptions
for truly generic code or testing propeties on `globalThis`.

There's still lots of TS work remaining (e.g. strictNullChecks,
strictPropertyInitialization, and cleaning up calendar.ts), but at least
we'll now have valid types on all functions.

I didn't find any runtime errors as a result of this work (good!) but I
did find quite a few problems with the public types in index.d.ts, and
this commit fixes those too.
justingrant added a commit to justingrant/temporal-polyfill that referenced this pull request Oct 10, 2021
This commit continues where js-temporal#74 left off by adding parameter and return
types to the rest of (non-ecmascript.ts) Temporal source files.

Also, it turns on --noImplicitAny.  The worst `any` offender is
calendar.ts, and fully declaring all its types is more work than
I want to take on in this PR, so I did an initial pass on obvious
types and assigned a lot of `any` for the rest. Will defnitely
need a follow up to improve calendar.ts.

Other than that one file, this commit essentially removes `any`
(implicit or otherwise) from the polyfill, with only a few exceptions
for truly generic code or testing propeties on `globalThis`.

There's still lots of TS work remaining (e.g. strictNullChecks,
strictPropertyInitialization, and cleaning up calendar.ts), but at least
we'll now have valid types on all functions.

I didn't find any runtime errors as a result of this work (good!) but I
did find quite a few problems with the public types in index.d.ts, and
this commit fixes those too.
justingrant added a commit to justingrant/temporal-polyfill that referenced this pull request Oct 10, 2021
This commit continues where js-temporal#74 left off by adding parameter and return
types to the rest of (non-ecmascript.ts) Temporal source files.

Also, it turns on --noImplicitAny.  The worst `any` offender is
calendar.ts, and fully declaring all its types is more work than
I want to take on in this PR, so I did an initial pass on obvious
types and assigned a lot of `any` for the rest. Will defnitely
need a follow up to improve calendar.ts.

Other than that one file, this commit essentially removes `any`
(implicit or otherwise) from the polyfill, with only a few exceptions
for truly generic code or testing propeties on `globalThis`.

There's still lots of TS work remaining (e.g. strictNullChecks,
strictPropertyInitialization, and cleaning up calendar.ts), but at least
we'll now have valid types on all functions.

I didn't find any runtime errors as a result of this work (good!) but I
did find quite a few problems with the public types in index.d.ts, and
this commit fixes those too.
justingrant added a commit to justingrant/temporal-polyfill that referenced this pull request Oct 10, 2021
This commit continues where js-temporal#74 left off by adding parameter and
return types to the rest of (non-ecmascript.ts) Temporal source files.

Also, it turns on --noImplicitAny.  The worst `any` offender is
calendar.ts, and fully declaring all its types is more work than I
want to take on in this PR, so I did an initial pass on obvious types
and assigned a lot of `any` for the rest. Will defnitely need a followup
PR to improve calendar.ts.

Other than that one file, this commit essentially removes `any`
(implicit or otherwise) from the polyfill, with only a few exceptions
for truly generic code or testing propeties on `globalThis`.

There's still lots of TS work remaining (e.g. `strictNullChecks`,
`strictPropertyInitialization`, and cleaning up calendar.ts), but at
least we'll now have valid types on all functions.

I didn't find any runtime errors as a result of this work (good!) but I
did find quite a few problems with the public types in index.d.ts, and
this commit fixes those too.
Copy link
Contributor

@Ms2ger Ms2ger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No objection from me

@12wrigja
Copy link
Contributor

Seems like the GH UI is doing something weird - I can't seem to respond to any of the open conversations unless I click "into" them, and even then the comments don't seem to propagate back.

I have no objections to merging this as-is and following up on my comments later, especially given some of them might be fixed by compiler flag changes (e.g. strictNullChecks).

justingrant added a commit to justingrant/temporal-polyfill that referenced this pull request Oct 11, 2021
This commit continues where js-temporal#74 left off by adding parameter and
return types to the rest of (non-ecmascript.ts) Temporal source files.

Also, it turns on --noImplicitAny.  The worst `any` offender is
calendar.ts, and fully declaring all its types is more work than I
want to take on in this PR, so I did an initial pass on obvious types
and assigned a lot of `any` for the rest. Will defnitely need a followup
PR to improve calendar.ts.

Other than that one file, this commit essentially removes `any`
(implicit or otherwise) from the polyfill, with only a few exceptions
for truly generic code or testing propeties on `globalThis`.

There's still lots of TS work remaining (e.g. `strictNullChecks`,
`strictPropertyInitialization`, and cleaning up calendar.ts), but at
least we'll now have valid types on all functions.

I didn't find any runtime errors as a result of this work (good!) but I
did find quite a few problems with the public types in index.d.ts, and
this commit fixes those too.
* Improves types for slots and intrinsics
* ecmascript.ts now has types throughout and compiles with
  `noImplicitAny` (although a later PR will actually enable this
  option)
* Fixes BigInt errors in a few places to fix compiler errors and
  test failures. Will be replaced by James's work on JSBI.
* Fixes a few index.d.ts bugs in the public types.
* Overhauls how plural units are handled in TS types.
* Partially adds types to calendar.ts. (More coming later.)
* A new internal types file for non-public shared types.
justingrant added a commit to justingrant/temporal-polyfill that referenced this pull request Oct 11, 2021
This commit continues where js-temporal#74 left off by adding parameter and
return types to the rest of (non-ecmascript.ts) Temporal source files.

Also, it turns on --noImplicitAny.  The worst `any` offender is
calendar.ts, and fully declaring all its types is more work than I
want to take on in this PR, so I did an initial pass on obvious types
and assigned a lot of `any` for the rest. Will defnitely need a followup
PR to improve calendar.ts.

Other than that one file, this commit essentially removes `any`
(implicit or otherwise) from the polyfill, with only a few exceptions
for truly generic code or testing propeties on `globalThis`.

There's still lots of TS work remaining (e.g. `strictNullChecks`,
`strictPropertyInitialization`, and cleaning up calendar.ts), but at
least we'll now have valid types on all functions.

I didn't find any runtime errors as a result of this work (good!) but I
did find quite a few problems with the public types in index.d.ts, and
this commit fixes those too.
@justingrant justingrant merged commit ac78fd9 into js-temporal:main Oct 11, 2021
justingrant added a commit to justingrant/temporal-polyfill that referenced this pull request Oct 11, 2021
This commit continues where js-temporal#74 left off by adding parameter and
return types to the rest of (non-ecmascript.ts) Temporal source files.

Also, it turns on --noImplicitAny.  The worst `any` offender is
calendar.ts, and fully declaring all its types is more work than I
want to take on in this PR, so I did an initial pass on obvious types
and assigned a lot of `any` for the rest. Will defnitely need a followup
PR to improve calendar.ts.

Other than that one file, this commit essentially removes `any`
(implicit or otherwise) from the polyfill, with only a few exceptions
for truly generic code or testing propeties on `globalThis`.

There's still lots of TS work remaining (e.g. `strictNullChecks`,
`strictPropertyInitialization`, and cleaning up calendar.ts), but at
least we'll now have valid types on all functions.

I didn't find any runtime errors as a result of this work (good!) but I
did find quite a few problems with the public types in index.d.ts, and
this commit fixes those too.
justingrant added a commit to justingrant/temporal-polyfill that referenced this pull request Oct 11, 2021
Continue where js-temporal#74 left off by adding parameter and return
types to the rest of (non-ecmascript.ts) Temporal source files.

Also, turn on `noImplicitAny`.  Except for calendar.ts, this PR
removes `any` (implicit or otherwise) from the polyfill, with only
a few exceptions for truly generic code or testing propeties on
`globalThis`.

For calendar.ts, `any` is removed from the top level `Calendar`
implementation and some of the `impl[]` code, but fully
declaring all types in that file was more work than I wanted to
take on in this PR. So I did an initial pass on obvious types and
assigned a lot of `any` for the rest. Will definitely need a followup
PR to improve calendar.ts. @12wrigja has discussed the possibility
of replacing the old-school inheritance using Object.apply with a
modern `class`-based implementation. If we're going to do that,
then it may make sense to fix the types then instead of on top of
the current solution.

Aside from calendar.ts, there's still lots of TS work remaining
(e.g. `strictNullChecks`, `strictPropertyInitialization`), but at least
we'll now have valid types on all functions.

I didn't find any runtime errors as a result of this work (good!) but I
did find quite a few problems with the public types in index.d.ts, and
this PR fixes those too. Once the dust settles and the changes are
reviewed, I can port a change back to proposal-temporal to keep
all public types in sync.
@12wrigja 12wrigja mentioned this pull request Oct 11, 2021
justingrant added a commit to justingrant/temporal-polyfill that referenced this pull request Oct 13, 2021
Continue where js-temporal#74 left off by adding parameter and return
types to the rest of (non-ecmascript.ts) Temporal source files.

Also, turn on `noImplicitAny`.  Except for calendar.ts, this PR
removes `any` (implicit or otherwise) from the polyfill, with only
a few exceptions for truly generic code or testing propeties on
`globalThis`.

For calendar.ts, `any` is removed from the top level `Calendar`
implementation and some of the `impl[]` code, but fully
declaring all types in that file was more work than I wanted to
take on in this PR. So I did an initial pass on obvious types and
assigned a lot of `any` for the rest. Will definitely need a followup
PR to improve calendar.ts. @12wrigja has discussed the possibility
of replacing the old-school inheritance using Object.apply with a
modern `class`-based implementation. If we're going to do that,
then it may make sense to fix the types then instead of on top of
the current solution.

Aside from calendar.ts, there's still lots of TS work remaining
(e.g. `strictNullChecks`, `strictPropertyInitialization`), but at least
we'll now have valid types on all functions.

I didn't find any runtime errors as a result of this work (good!) but I
did find quite a few problems with the public types in index.d.ts, and
this PR fixes those too. Once the dust settles and the changes are
reviewed, I can port a change back to proposal-temporal to keep
all public types in sync.
justingrant added a commit that referenced this pull request Oct 13, 2021
Continue where #74 left off by adding parameter and return
types to the rest of (non-ecmascript.ts) Temporal source files.

Also, turn on `noImplicitAny`.  Except for calendar.ts, this PR
removes `any` (implicit or otherwise) from the polyfill, with only
a few exceptions for truly generic code or testing propeties on
`globalThis`.

For calendar.ts, `any` is removed from the top level `Calendar`
implementation and some of the `impl[]` code, but fully
declaring all types in that file was more work than I wanted to
take on in this PR. So I did an initial pass on obvious types and
assigned a lot of `any` for the rest. Will definitely need a followup
PR to improve calendar.ts. @12wrigja has discussed the possibility
of replacing the old-school inheritance using Object.apply with a
modern `class`-based implementation. If we're going to do that,
then it may make sense to fix the types then instead of on top of
the current solution.

Aside from calendar.ts, there's still lots of TS work remaining
(e.g. `strictNullChecks`, `strictPropertyInitialization`), but at least
we'll now have valid types on all functions.

I didn't find any runtime errors as a result of this work (good!) but I
did find quite a few problems with the public types in index.d.ts, and
this PR fixes those too. Once the dust settles and the changes are
reviewed, I can port a change back to proposal-temporal to keep
all public types in sync.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants