Skip to content
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

Fix "implicit any" Typescript errors to prepare for Typescript 5.5 #1817

Merged
merged 3 commits into from
May 27, 2024

Conversation

rmunn
Copy link
Collaborator

@rmunn rmunn commented May 22, 2024

Fixes #1800

Description

We currently have suppressImplicitAnyIndexErrors in our tsconfig.json since we have a lot of implicit any types scattered throughout our code. That option will be going away in Typescript 5.5, so we need to fix them now so that we can continue to upgrade Typescript in the future (5.5 is currently in beta).

Screenshots

No behavioral changes.

Checklist

  • I have labeled my PR with: bug, feature, engineering, security fix or testing
  • I have performed a self-review of my own code
  • I have reviewed the title & description of this PR which I will use as the squashed PR commit message
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • I have enabled auto-merge (optional)

Testing

Testers, use the following instructions against our staging environment. Post your findings as a comment and include any meaningful screenshots, etc.

  • Run make, make sure site still loads.
  • Check that there aren't more Typescript errors showing up in VS Code.

rmunn added 3 commits May 21, 2024 16:48
Typescript 5.5 disallows the "suppressImplicitAnyIndexErrors", so we
need to go through the code, find any places where an index has an
implicit "any" type, and annotate those places with the correct type so
that Typescript won't complain about them.

This commit makes a start on this task.
In a couple places, we do `if foo.hasOwnProperty(bar)` followed by
getting the value of `foo[bar]`, but Typescript warns that "string"
isn't a valid property name of `foo`. It should recognize that the
hasOwnProperty check means it's safe to access `foo[bar]`, but it
doesn't. We can either change those to be `if bar in foo` which
Typescript *does* recognize as a type guard, or else we can just leave
the code as-is and add @ts-expect-error comments. Since `bar in foo` is
not quite identical to `foo.hasOwnProperty(bar)` (`bar in foo` climbs
inheritance hierarchies whereas `.hasOwnProperty` doesn't), I chose to
leave the code as-is rather than subtly change its behavior.
Now that we've fixed the implicit "any" index errors, we can remove this
line from tsconfig. (It will be going away in Typescript 5.5 anyway).
@rmunn rmunn added the engineering Tasks which do not directly relate to a user-facing feature or fix label May 22, 2024
@rmunn rmunn self-assigned this May 22, 2024
Copy link

Unit Test Results

362 tests   362 ✅  13s ⏱️
 37 suites    0 💤
  1 files      0 ❌

Results for commit c92e2e6.

@rmunn rmunn requested a review from megahirt May 22, 2024 06:18
@rmunn rmunn merged commit 9f51fab into develop May 27, 2024
17 checks passed
@rmunn rmunn deleted the debt/typescript-5.5-prep branch May 27, 2024 05:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
engineering Tasks which do not directly relate to a user-facing feature or fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

debt: suppressImplicitAnyIndexErrors will be disallowed in Typescript 5.5
3 participants