Skip to content

fix(beacon-node): cast emitter at the failing emit site to fix tsgo overload - #9491

Merged
nflaig merged 1 commit into
ChainSafe:te/fix_block_input_sync_metrics_logsfrom
lodekeeper:fix/tsgo-emitter-cast
Jun 9, 2026
Merged

fix(beacon-node): cast emitter at the failing emit site to fix tsgo overload#9491
nflaig merged 1 commit into
ChainSafe:te/fix_block_input_sync_metrics_logsfrom
lodekeeper:fix/tsgo-emitter-cast

Conversation

@lodekeeper

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #9488 — the restructure removed the let ! + destructuring pattern but tsgo's overload-resolution miss persists at the same emit site because emitter is also captured by a sibling closure (the processBlock mock body that emits routes.events.EventType.block). Same TS2769 error reproduces on the current head:

test/unit/sync/unknownBlock.test.ts(1027,20): error TS2769: No overload matches this call.
  Argument of type 'ChainEvent.unknownEnvelopeBlockRoot' is not assignable to parameter of type 'unique symbol'.

Fix

Cast emitter at the failing site to ChainEventEmitter to re-anchor the StrictEventEmitter overload for ChainEvent.X keys. Minimal change — single line cast at line 1023, with a comment explaining why. The 5 other emitter.emit(ChainEvent.unknownEnvelopeBlockRoot, ...) sites in the file remain untouched because they aren't reached through a sibling closure capture.

The previous restructure (now in the base branch) is still worth keeping — it removed an unnecessary indirection — but it wasn't sufficient on its own.

Test plan

  • CI: Type Checks (24) passes (no TS2769 on unknownBlock.test.ts).
  • CI: unit tests for the "downloads the block and retries payload import when EL reports block not in fork choice" test still pass — emit semantics unchanged.

🤖 Generated with Claude Code

…verload

The previous restructure (ChainSafe#9488) removed the let !+destructuring pattern
but tsgo still picks the wrong emit overload for ChainEvent.X at this site
when emitter is captured by a sibling closure (the processBlock mock that
emits routes.events.EventType.block).

Same TS2769 error reproduces:

  test/unit/sync/unknownBlock.test.ts(1027,20): error TS2769:
  No overload matches this call.
  Argument of type 'ChainEvent.unknownEnvelopeBlockRoot' is not assignable
  to parameter of type 'unique symbol'.

Apply an explicit (emitter as ChainEventEmitter) cast at the failing call
site to re-anchor the StrictEventEmitter overload. Minimal change; the
5 other emitter.emit(ChainEvent.unknownEnvelopeBlockRoot, ...) sites in
the file remain unchanged because they aren't reached through a sibling
closure capture.

🤖 Generated with AI assistance
@lodekeeper
lodekeeper requested a review from a team as a code owner June 9, 2026 12:05

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates a unit test in unknownBlock.test.ts by casting emitter to ChainEventEmitter when emitting ChainEvent.unknownEnvelopeBlockRoot to resolve a TypeScript overload-resolution issue. There are no review comments, and I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@nflaig
nflaig merged commit 9b2aa84 into ChainSafe:te/fix_block_input_sync_metrics_logs Jun 9, 2026
15 of 16 checks passed
nflaig pushed a commit that referenced this pull request Jun 9, 2026
…emit (#9492)

## Summary

The base-branch update brought in #9479's new test ("defers envelope
validation until the block is in fork choice when payload input is
seeded from the block body") which uses the same `let emitter!:
ChainEventEmitter` + destructuring-assignment + sibling closure capture
pattern that #9491 already mitigated in the original failing test below.
Same `TS2769` fires at the new test's emit site:

```
test/unit/sync/unknownBlock.test.ts(1027,20): error TS2769: No overload matches this call.
  Argument of type 'ChainEvent.unknownEnvelopeBlockRoot' is not assignable to parameter of type 'unique symbol'.
```

Also, #9479's emit predates this PR's addition of `slot: Slot` to the
`ChainEvent.unknownEnvelopeBlockRoot` event signature, so the emit data
is missing the required `slot` field after the merge.

## Fix

Same minimal cast workaround as #9491 plus the required `slot: 0` field:

```diff
-      emitter.emit(ChainEvent.unknownEnvelopeBlockRoot, {
+      // tsgo overload-resolution miss when emit is reached through a closure that captures emitter
+      // first; cast re-anchors the StrictEventEmitter overload for ChainEvent keys (see #9491).
+      (emitter as ChainEventEmitter).emit(ChainEvent.unknownEnvelopeBlockRoot, {
         rootHex: blockRootHex,
+        slot: 0,
         peer,
         source: BlockInputSource.gossip,
       });
```

Single-site change. The 5 other
`emitter.emit(ChainEvent.unknownEnvelopeBlockRoot, ...)` sites in the
file remain unchanged because they aren't reached through a sibling
closure capture; the cast at the sibling test's emit (introduced in
#9491, currently at line 1126) also remains as-is and continues to
typecheck cleanly with the expanded `EventType` union from #9439.

## Test plan

- [ ] CI: `Type Checks (24)` passes (no TS2769 on
`unknownBlock.test.ts`).
- [ ] CI: the new `defers envelope validation until the block is in fork
choice when payload input is seeded from the block body` test still
passes — emit semantics unchanged.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: lodekeeper <lodekeeper@users.noreply.github.com>
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.

2 participants