Skip to content

Conversation

@adityajha2005
Copy link
Contributor

Summary

This PR fixes TypeScript build errors in flux-client and ensures the project builds cleanly without type errors.

What’s fixed

  • Corrected the return type assertion for createGrpcClient
  • Fixed the async iterator typing for the messageStream bidirectional stream
  • Resolved all remaining TypeScript errors related to gRPC stream handling

Result

  • TypeScript build now passes successfully
  • No runtime behavior changes
  • Improved type safety and developer experience

Notes

  • Changes are limited to typing fixes only
  • Verified by reproducing the failing build and confirming a clean build after the fix

Build status

Before

After

- Fix type assertion for createGrpcClient return type
- Fix async iterator type for messageStream bidi stream
- All TypeScript errors resolved, build passes
@adityajha2005
Copy link
Contributor Author

Only src/flux-client.ts contains functional changes - the other diffs are no-ops from re-syncing with upstream main.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses TypeScript build errors in flux-client.ts by adding type assertions to resolve compilation issues with gRPC client creation and stream handling. The changes include formatting fixes (adding newlines at end of files) and two type assertions aimed at satisfying TypeScript's type checker.

Key Changes

  • Added type assertion for createGrpcClient return value using as unknown as pattern
  • Added type assertion for bidirectional gRPC stream with single-element tuple destructuring
  • Added trailing newlines to index.ts and agent-loader.ts for consistency

Reviewed changes

Copilot reviewed 1 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/flux-client.ts Added type assertions to fix TypeScript compilation errors for gRPC client initialization and message stream iteration
src/index.ts Added trailing newline at end of file
src/agent-loader.ts Added trailing newline at end of file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

});

this.client = await createGrpcClient(GRPC_SERVER_ADDRESS, clientImpl);
this.client = (await createGrpcClient(GRPC_SERVER_ADDRESS, clientImpl)) as unknown as Awaited<ReturnType<typeof createGrpcClient>>;
Copy link

Copilot AI Dec 28, 2025

Choose a reason for hiding this comment

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

This type assertion is redundant and potentially problematic. The expression casts the result of createGrpcClient to Awaited<ReturnType<typeof createGrpcClient>>, which is the same type it already returns. Using as unknown as to cast something to its own type suggests a workaround for a type system issue that should be addressed differently.

Looking at line 9, the client property is already typed as Awaited<ReturnType<typeof createGrpcClient>> | null, and auth.ts uses createGrpcClient without any type assertions (lines 80, 88, 113, 170, 187). The assertion should be removed entirely, allowing TypeScript to infer the correct type naturally.

Suggested change
this.client = (await createGrpcClient(GRPC_SERVER_ADDRESS, clientImpl)) as unknown as Awaited<ReturnType<typeof createGrpcClient>>;
this.client = await createGrpcClient(GRPC_SERVER_ADDRESS, clientImpl);

Copilot uses AI. Check for mistakes.
(async () => {
for await (const [message] of this.client!.FluxService.messageStream) {
const stream = this.client!.FluxService.messageStream;
for await (const [message] of stream as AsyncIterable<[IncomingMessage | { ack: string }]>) {
Copy link

Copilot AI Dec 28, 2025

Choose a reason for hiding this comment

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

The destructuring pattern and type assertion here appear unusual. The type assertion declares that the stream yields tuples [IncomingMessage | { ack: string }], but this single-element tuple pattern is unconventional.

Typically, bidirectional gRPC streams would either:

  1. Yield values directly: for await (const message of stream as AsyncIterable<IncomingMessage | { ack: string }>)
  2. Yield multi-element tuples if there's metadata: for await (const [message, metadata] of stream)

Verify that the better-grpc library actually yields single-element tuples, or simplify the destructuring if the tuple wrapper is unnecessary.

Suggested change
for await (const [message] of stream as AsyncIterable<[IncomingMessage | { ack: string }]>) {
for await (const message of stream as AsyncIterable<IncomingMessage | { ack: string }>) {

Copilot uses AI. Check for mistakes.
@garygao333
Copy link
Collaborator

Thanks! This is really helpful. We’ll definitely merge it if this build issue starts showing up more.

@underthestars-zhy
Copy link
Member

The client should already be properly typed, and adding a type assertion here would cause issues in the type system. @adityajha2005 would you mind opening an issue for this instead?

@adityajha2005
Copy link
Contributor Author

The client should already be properly typed, and adding a type assertion here would cause issues in the type system. @adityajha2005 would you mind opening an issue for this instead?

Sure, that makes sense. I’ll open an issue with the details and reproduction steps.

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.

3 participants