Skip to content

refactor: remove redundant as-any casts in event-stream and agent#3331

Open
oldschoola wants to merge 2 commits into
can1357:mainfrom
oldschoola:fix/event-stream-undefined-as-any
Open

refactor: remove redundant as-any casts in event-stream and agent#3331
oldschoola wants to merge 2 commits into
can1357:mainfrom
oldschoola:fix/event-stream-undefined-as-any

Conversation

@oldschoola

Copy link
Copy Markdown
Contributor

Summary

Removes 3 redundant as any casts across two packages:

packages/ai/src/utils/event-stream.ts

EventStream.end() and endWaiting() resolved waiting consumers with { value: undefined as any, done: true }. The as any cast is unnecessary — IteratorResult<T> is IteratorYieldResult<T> | IteratorReturnResult<TReturn> where TReturn defaults to any, so undefined is assignable to the value field when done: true.

packages/agent/src/agent.ts

The turn_end handler accessed errorMessage via (event.message as any).errorMessage. The errorMessage field is already on the AssistantMessage interface (packages/ai/src/types.ts:524), so the cast is unnecessary.

Verification

  • bun check passes
  • 81 tests pass across agent.test.ts, agent-loop.test.ts, yield.test.ts, proxy-stream-disconnect.test.ts

- EventStream.end()/endWaiting(): removed 'undefined as any' casts.
  IteratorResult<T> already allows undefined for value when done:true.
- Agent turn_end handler: removed (event.message as any).errorMessage
  casts — errorMessage is already on the AssistantMessage type.
@github-actions github-actions Bot added the vouched Passed the vouch gate label Jun 23, 2026
@roboomp roboomp added agent Agent runtime planning and orchestration refactor review:p1 sdk SDK and extension integration surface triaged labels Jun 23, 2026

@roboomp roboomp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

P1: small, coherent cleanup with changelog coverage; bun check passed locally.
One should-fix: packages/ai/src/utils/event-stream.ts still leans on IteratorResult<T>'s implicit any return type instead of tightening the waiter result to undefined.
No duplicate/superseding PR found in the GitHub search results for this fix. Thanks for the cleanup.

while (this.waiting.length > 0) {
const waiter = this.waiting.shift()!;
waiter.resolve({ value: undefined as any, done: true });
waiter.resolve({ value: undefined, done: true });

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

should-fix This still type-checks because waiting.resolve is typed as IteratorResult<T>, whose TReturn defaults to any. That removes the as any text but keeps the same implicit any escape hatch for both done: true resolves. Could we type the waiter result and the promise in [Symbol.asyncIterator] as IteratorResult<T, undefined> instead, so undefined is checked without relying on any?

…ing on TReturn=any

Address review feedback: typing the waiter result and the Promise in
the async iterator as IteratorResult<T, undefined> makes the undefined
value explicit instead of relying on the default TReturn=any escape
hatch.
@oldschoola

Copy link
Copy Markdown
Contributor Author

Good point — addressed in the latest push. The waiter type and the Promise in the async iterator are now explicitly typed as IteratorResult<T, undefined> instead of the default IteratorResult<T, any>, so the undefined value is type-checked without relying on the implicit any for TReturn.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent Agent runtime planning and orchestration refactor review:p1 sdk SDK and extension integration surface triaged vouched Passed the vouch gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants