Skip to content

Missing RpcError in exports.js (among other classes), inconsistent with index.d.ts #1158

Closed
@roemba

Description

@roemba

A relatively simple issue but I think quite important:
The index.d.ts contains definitions like the following (grpc-web = 1.3.0):

  export class UnaryResponse<REQ, RESP> {
    getResponseMessage(): RESP;
    getMetadata(): Metadata;
    getMethodDescriptor(): MethodDescriptor<REQ, RESP>;
    getStatus(): Status;
  }
  export class GrpcWebClientBase extends AbstractClientBase {
    constructor(options?: GrpcWebClientBaseOptions);
  }

  export class RpcError extends Error {
    constructor(code: StatusCode, message: string, metadata: Metadata);
    code: StatusCode;
    metadata: Metadata;
  }

There is nothing wrong with these definitions and they are very useful. However, exporting a class implies that I must be able to extend them, e.g. the following must work (and indeed compiles fine in Typescript):

class GRPCCallbackError extends RpcError {
  callId: string

  constructor (code: StatusCode, message: string, metadata: Metadata, callId: string) {
    super(code, message, metadata)
    this.callId = callId
  }
}

However, running this code throws an TypeError: Class extends value undefined is not a constructor or null because index.js of grpc-web does not actually export the RpcError class (or the UnaryResponse class for that matter). I confirmed this by checking grpc-web/packages/grpc-web/exports.js where only GrpcWebClientBase, StatusCode, MethodDescriptor and MethodType are exported by grpc-web.

Suggested fix:
Either change the index.d.ts to reflect that some classes are not exported or change exports.js to also export the classes that are exported in index.d.ts. I prefer the latter as that makes grpc-web more extendable.

If you think this is a good idea, I can create a merge-request for it in the coming week.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions