From 0793a8e2318f9355b8e65cab525b5ccbd5fba833 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 11 May 2026 10:04:55 -0700 Subject: [PATCH] chore(superset-ui-switchboard): forward-compat fixes for TypeScript 6.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Phase E of the TS 5.4 → 6.0 migration tracked in #39539. Scoped to packages/superset-ui-switchboard. Compiles cleanly under both TS 5.4.5 (current CI pin) and TS 6.0.3, eliminating 5 TS 6.0 errors: - 3 × TS2564 (strict property initialization) in switchboard.ts — Switchboard class fields `port`, `debugMode`, `isInitialised` had no initializer and weren't assigned in the constructor (they're set later in `init()`). Added definite- assignment `!` to `port` (no sensible default; class is unusable pre-init) and initialized `debugMode`/`isInitialised` to `false`, which matches the runtime defaults already used in `init()`. - 2 × TS2322 (FakeMessagePort/MessagePort mismatch) in switchboard.test.ts — TS 6.0's stricter inference rejects assigning a FakeMessagePort to `MessagePort` because `addEventListener`'s overload set no longer accepts the simpler `(event: 'message', handler: EventHandler) => void` signature. The fake only implements the subset of MessagePort that Switchboard exercises, so we cast at the assignment with `as unknown as MessagePort` per the playbook (targeted boundary casts, no widening of the production type). `packages/generator-superset` was in scope but has zero TS 6.0 source errors, so it's left untouched. No runtime behavior changes. Switchboard's 13 jest tests still pass. Part of the TypeScript 5.4 → 6.0 migration, split per-package to keep reviews small. See #39539 for the full roadmap. Co-Authored-By: Claude Opus 4.7 --- .../superset-ui-switchboard/src/switchboard.test.ts | 7 +++++-- .../packages/superset-ui-switchboard/src/switchboard.ts | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/superset-frontend/packages/superset-ui-switchboard/src/switchboard.test.ts b/superset-frontend/packages/superset-ui-switchboard/src/switchboard.test.ts index 5bfe77903ff..352c508b2e8 100644 --- a/superset-frontend/packages/superset-ui-switchboard/src/switchboard.test.ts +++ b/superset-frontend/packages/superset-ui-switchboard/src/switchboard.test.ts @@ -95,8 +95,11 @@ class FakeMessageChannel { const port2 = new FakeMessagePort(); port1.otherPort = port2; port2.otherPort = port1; - this.port1 = port1; - this.port2 = port2; + // FakeMessagePort only implements the subset of MessagePort that + // Switchboard exercises; cast at the boundary so the fake satisfies + // the consumer signature without weakening the production type. + this.port1 = port1 as unknown as MessagePort; + this.port2 = port2 as unknown as MessagePort; } } diff --git a/superset-frontend/packages/superset-ui-switchboard/src/switchboard.ts b/superset-frontend/packages/superset-ui-switchboard/src/switchboard.ts index d1df6136a50..46af6fb4d3e 100644 --- a/superset-frontend/packages/superset-ui-switchboard/src/switchboard.ts +++ b/superset-frontend/packages/superset-ui-switchboard/src/switchboard.ts @@ -88,7 +88,7 @@ function isError(message: Message): message is ErrorMessage { * Calling methods on the switchboard causes messages to be sent through the channel. */ export class Switchboard { - port: MessagePort; + port!: MessagePort; name = ''; @@ -97,9 +97,9 @@ export class Switchboard { // used to make unique ids incrementor = 1; - debugMode: boolean; + debugMode = false; - private isInitialised: boolean; + private isInitialised = false; constructor(params?: Params) { if (!params) {