Skip to content

Commit

Permalink
Fix ClientOptions types
Browse files Browse the repository at this point in the history
Remove index signature from ChannelOptions to fix intersection error
described in grpc#1558 which causes issues on using ClientOptions direct
fields with TypeScript.

Removing of index signature required few minor changes:
 - adding few constant types that were used throughout the app
 - using `as const` assertion in xds-client
 - using not-so-great type cast in channelOptionsEqual

Alternative solution would be removing the index signature from
ChannelOptions explicitly in ClientOptions definition, which is not
trivial and probably calls for a generic type helper.

See: grpc#1558
Fixes: grpc#1558
  • Loading branch information
smolijar committed Sep 1, 2020
1 parent 4b9da2e commit 56241fe
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/grpc-js/src/channel-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export interface ChannelOptions {
'grpc.max_send_message_length'?: number;
'grpc.max_receive_message_length'?: number;
'grpc.enable_http_proxy'?: number;
[key: string]: string | number | undefined;
'grpc.http_connect_target'?: string;
'grpc.http_connect_creds'?: string;
[key: string]: any;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/grpc-js/src/xds-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,7 @@ export class XdsClient {
* recursively using an xDS load balancer for the xDS client would be
* bad */
'grpc.service_config',
];
] as const;
for (const arg of channelArgsToRemove) {
delete channelArgs[arg];
}
Expand Down

0 comments on commit 56241fe

Please sign in to comment.