You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ClientOptions type is intersection of its definition and Partial<ChannelOptions>. Partial<ChannelOptions> defines constants and index signature [key: string]: string | number | undefined;, which contradicts with ClientOptions defintions: Since intersection is used, all string attributes of ClientOptions are required to be string | number | undefined, which contradicts for example ClientOptions's interceptors, which is array of functions.
This issue makes the new interceptor unusable with TS without force-casting.
Reproduction steps
import{Interceptor,Client,ChannelCredentials}from"@grpc/grpc-js";constinterceptor=(nullasany)asInterceptor;// just type demonstrationnewClient("",ChannelCredentials.createInsecure(),{interceptors: [interceptor],// triggers error, whole options object});
Argument of type '{ interceptors: Interceptor[]; }' is not assignable to parameter of type 'ClientOptions'.
Type '{ interceptors: Interceptor[]; }' is not assignable to type 'Partial<ChannelOptions>'.
Property 'interceptors' is incompatible with index signature.
Type 'Interceptor[]' is not assignable to type 'string | number'.
Type 'Interceptor[]' is not assignable to type 'string'.
Environment
@grpc/js 1.1.5
Tested on TS 4.0.2 and 3.9.7
Additional context
We could solve this either by removing the index signature or removing it before the type intersection, which is a bit hard on eyes with generics. Will try to post a PR soon.
The text was updated successfully, but these errors were encountered:
smolijar
added a commit
to smolijar/grpc-node
that referenced
this issue
Sep 1, 2020
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: 1558
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#1558Fixes: grpc#1558
Problem description
ClientOptions type is intersection of its definition and
Partial<ChannelOptions>
.Partial<ChannelOptions>
defines constants and index signature[key: string]: string | number | undefined;
, which contradicts with ClientOptions defintions: Since intersection is used, all string attributes of ClientOptions are required to bestring | number | undefined
, which contradicts for example ClientOptions'sinterceptors
, which is array of functions.This issue makes the new interceptor unusable with TS without force-casting.
Reproduction steps
Environment
Additional context
We could solve this either by removing the index signature or removing it before the type intersection, which is a bit hard on eyes with generics. Will try to post a PR soon.
The text was updated successfully, but these errors were encountered: