Skip to content

Commit

Permalink
fix: Extend global.Error to avoid import collisions with Error prot…
Browse files Browse the repository at this point in the history
…o 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 <stephen.haberman@gmail.com>
  • Loading branch information
MorganIsBatman and stephenh committed Nov 13, 2022
1 parent 5b14735 commit e9d8f91
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion integration/grpc-web-no-streaming-observable/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion integration/grpc-web-no-streaming/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion integration/grpc-web/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit e9d8f91

Please sign in to comment.