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 #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: #1558
Fixes: 1558
  • Loading branch information
smolijar committed Sep 1, 2020
1 parent 4b9da2e commit 3301e60
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions packages/grpc-js/src/channel-options.ts
Expand Up @@ -33,7 +33,8 @@ 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;
}

/**
Expand Down Expand Up @@ -70,7 +71,7 @@ export function channelOptionsEqual(
if (keys1[i] !== keys2[i]) {
return false;
}
if (options1[keys1[i]] !== options2[keys2[i]]) {
if (options1[keys1[i] as keyof ChannelOptions] !== options2[keys2[i] as keyof ChannelOptions]) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/grpc-js/src/xds-client.ts
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 3301e60

Please sign in to comment.