Compare commits

...

1 Commits

Author SHA1 Message Date
Claude
0793a8e231 chore(superset-ui-switchboard): forward-compat fixes for TypeScript 6.0
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 <noreply@anthropic.com>
2026-05-11 16:58:25 -07:00
2 changed files with 8 additions and 5 deletions

View File

@@ -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;
}
}

View File

@@ -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) {