From e9d8f9123b7b3c5e274035fa3f2644b370915181 Mon Sep 17 00:00:00 2001 From: Morgan Hall Date: Mon, 14 Nov 2022 03:44:20 +1300 Subject: [PATCH] fix: Extend `global.Error` to avoid import collisions with Error proto msgs (#699) * Extend `global.Error` to avoid import collisions with Error proto messages We have an `Error` proto that causes typescript issues when imported into the proto file of a service definition, as the `export class GrpcWebError extends Error` added to the output .ts files for the service think we're trying to extend our type, not the js type. Change here is to simply use `global.Error` to avoid the issue * run yarn build:test:local * switch from global.Error to globalThis.Error This based on feedback from someone in my team using Vite and importing the .ts file rather than the compiled .js file - using `global` errors as its declared in the same file * Run proto2bin. Co-authored-by: Stephen Haberman --- integration/grpc-web-no-streaming-observable/example.ts | 2 +- integration/grpc-web-no-streaming/example.ts | 2 +- integration/grpc-web/example.ts | 2 +- src/main.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/integration/grpc-web-no-streaming-observable/example.ts b/integration/grpc-web-no-streaming-observable/example.ts index 3c2bdc5f2..ea9642f05 100644 --- a/integration/grpc-web-no-streaming-observable/example.ts +++ b/integration/grpc-web-no-streaming-observable/example.ts @@ -429,7 +429,7 @@ function isSet(value: any): boolean { return value !== null && value !== undefined; } -export class GrpcWebError extends Error { +export class GrpcWebError extends globalThis.Error { constructor(message: string, public code: grpc.Code, public metadata: grpc.Metadata) { super(message); } diff --git a/integration/grpc-web-no-streaming/example.ts b/integration/grpc-web-no-streaming/example.ts index bbf9663cd..834263b73 100644 --- a/integration/grpc-web-no-streaming/example.ts +++ b/integration/grpc-web-no-streaming/example.ts @@ -426,7 +426,7 @@ function isSet(value: any): boolean { return value !== null && value !== undefined; } -export class GrpcWebError extends Error { +export class GrpcWebError extends globalThis.Error { constructor(message: string, public code: grpc.Code, public metadata: grpc.Metadata) { super(message); } diff --git a/integration/grpc-web/example.ts b/integration/grpc-web/example.ts index 52a451c85..75c03351e 100644 --- a/integration/grpc-web/example.ts +++ b/integration/grpc-web/example.ts @@ -903,7 +903,7 @@ function isSet(value: any): boolean { return value !== null && value !== undefined; } -export class GrpcWebError extends Error { +export class GrpcWebError extends globalThis.Error { constructor(message: string, public code: grpc.Code, public metadata: grpc.Metadata) { super(message); } diff --git a/src/main.ts b/src/main.ts index d083f73cf..cc4863be7 100644 --- a/src/main.ts +++ b/src/main.ts @@ -702,7 +702,7 @@ function makeGrpcWebErrorClass() { const GrpcWebError = conditionalOutput( "GrpcWebError", code` - export class GrpcWebError extends Error { + export class GrpcWebError extends globalThis.Error { constructor(message: string, public code: grpc.Code, public metadata: grpc.Metadata) { super(message); }