pixiebrix-extension icon indicating copy to clipboard operation
pixiebrix-extension copied to clipboard

Incremental strictNullChecks adoption - Slice X (add contentScript/messenger/api.ts)

Open mnholtz opened this issue 2 years ago • 7 comments

Follow-up of https://github.com/pixiebrix/pixiebrix-extension/issues/6498 contentScript/messenger/api.ts is being split off because of the 700 ts errors that need to be resolved from adding it

mnholtz avatar Sep 26 '23 17:09 mnholtz

We'll keep this one on the back-burner for now. Once other low-hanging fruit have been fixed, we'll try again.

grahamlangford avatar Sep 26 '23 17:09 grahamlangford

As of https://github.com/pixiebrix/pixiebrix-extension/pull/6590, there are still 605 errors that would need to be resolved.

grahamlangford avatar Oct 03 '23 14:10 grahamlangford

As discussed with Graham on Slack, this file is high up in the suggested files to fix because it's a funnel file:

  • api.ts has 48 exports. In reality, each export is not as important on its own as this metric makes it seem.

We should essentially ignore this these files and treat them as entry points:

  • registration.ts imports from lots of parts of the extension (30 direct imports + their sub dependencies).

I suggest tackling the rest of the migration list for now, these files will naturally trigger fewer errors.

We could alternatively add each of those 30 imports to the strictNullChecks config, but again individually they're not as important as they seem.

fregante avatar Oct 10 '23 07:10 fregante

Need to remove temporary typing in src/sidebar/messenger/registration.ts. See https://github.com/pixiebrix/pixiebrix-extension/pull/6650/files#r1355092186

grahamlangford avatar Oct 11 '23 14:10 grahamlangford

We can unblock many of these files by creating additional entry points for common methods like recordEvent, which is imported directly by 60 files:

- import { recordEvent } from "@/background/messenger/api";
+ import { recordEvent } from "@/background/messenger/api-strict";
or
+ import { recordEvent } from "@/background/strict/messenger/api";

This, together with a "strict" registration.ts file, can help migrate more and more common methods to being strict, instead of having to tackle all of the 700 errors in a single PR (or never tackling this at all)

fregante avatar Oct 25 '23 08:10 fregante

We can unblock many of these files by creating additional entry points for common methods like recordEvent, which is imported directly by 60 files:

- import { recordEvent } from "@/background/messenger/api";
+ import { recordEvent } from "@/background/messenger/api-strict";
or
+ import { recordEvent } from "@/background/strict/messenger/api";

This, together with a "strict" registration.ts file, can help migrate more and more common methods to being strict, instead of having to tackle all of the 700 errors in a single PR (or never tackling this at all)

This sounds like a good approach.

It is also worth noting that adding the two files now generates 570 errors, so working on other files first is slowly decreasing the overall load here.

grahamlangford avatar Oct 25 '23 12:10 grahamlangford

If you encounter the keyof MessengerMethods issue when working on unrelated files:

  • reorganize the code to avoid causing the non-strict messenger to be imported, e.g. don't place your new code in a non-strict file that uses the Messenger.
  • if you're directly importing a method from messenger/api.ts, try moving it to messenger/strict/api.ts and fixing the errors as suggested in the section below.

Here's how to gradually migrate messenger files:

  1. Move an import from registration.ts to strict/registration.ts (the whole imported file, not just a method)
  2. Fix the type errors that arise, if possible
  3. Move its methods from api.ts to strict/api.ts as well.
  4. Update the imports and mocks across the extension

fregante avatar Feb 05 '24 07:02 fregante