Skip to content

Commit

Permalink
fix: Use as any on globalThis.Buffer check for bytesFromBase64 (#1005)
Browse files Browse the repository at this point in the history
This is a follow up PR for #1004 which also add `as any` for the
`bytesFromBase64` function to make it work fully with strict tsconfig
setting. See #967.
  • Loading branch information
jonaskello authored Feb 18, 2024
1 parent 308d27a commit bae741c
Show file tree
Hide file tree
Showing 25 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ export const BytesValue = {
};

function bytesFromBase64(b64: string): Uint8Array {
if (globalThis.Buffer) {
if ((globalThis as any).Buffer) {
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
} else {
const bin = globalThis.atob(b64);
Expand Down
2 changes: 1 addition & 1 deletion integration/bytes-as-base64/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const Message = {
};

function bytesFromBase64(b64: string): Uint8Array {
if (globalThis.Buffer) {
if ((globalThis as any).Buffer) {
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
} else {
const bin = globalThis.atob(b64);
Expand Down
2 changes: 1 addition & 1 deletion integration/emit-default-values-json/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ export const Child = {
};

function bytesFromBase64(b64: string): Uint8Array {
if (globalThis.Buffer) {
if ((globalThis as any).Buffer) {
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
} else {
const bin = globalThis.atob(b64);
Expand Down
2 changes: 1 addition & 1 deletion integration/grpc-js/google/protobuf/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ export const BytesValue = {
};

function bytesFromBase64(b64: string): Uint8Array {
if (globalThis.Buffer) {
if ((globalThis as any).Buffer) {
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
} else {
const bin = globalThis.atob(b64);
Expand Down
2 changes: 1 addition & 1 deletion integration/grpc-web/google/protobuf/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ export const BytesValue = {
};

function bytesFromBase64(b64: string): Uint8Array {
if (globalThis.Buffer) {
if ((globalThis as any).Buffer) {
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
} else {
const bin = globalThis.atob(b64);
Expand Down
2 changes: 1 addition & 1 deletion integration/nice-grpc/google/protobuf/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ export const BytesValue = {
};

function bytesFromBase64(b64: string): Uint8Array {
if (globalThis.Buffer) {
if ((globalThis as any).Buffer) {
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
} else {
const bin = globalThis.atob(b64);
Expand Down
2 changes: 1 addition & 1 deletion integration/oneof-properties/oneof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ export const PleaseChoose_Submessage = {
};

function bytesFromBase64(b64: string): Uint8Array {
if (globalThis.Buffer) {
if ((globalThis as any).Buffer) {
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
} else {
const bin = globalThis.atob(b64);
Expand Down
2 changes: 1 addition & 1 deletion integration/oneof-unions/oneof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ export const SimpleButOptional = {
};

function bytesFromBase64(b64: string): Uint8Array {
if (globalThis.Buffer) {
if ((globalThis as any).Buffer) {
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
} else {
const bin = globalThis.atob(b64);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export const BytesValue = {
};

function bytesFromBase64(b64: string): Uint8Array {
if (globalThis.Buffer) {
if ((globalThis as any).Buffer) {
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
} else {
const bin = globalThis.atob(b64);
Expand Down
2 changes: 1 addition & 1 deletion integration/simple-long-bigint/google/protobuf/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ export const BytesValue = {
};

function bytesFromBase64(b64: string): Uint8Array {
if (globalThis.Buffer) {
if ((globalThis as any).Buffer) {
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
} else {
const bin = globalThis.atob(b64);
Expand Down
2 changes: 1 addition & 1 deletion integration/simple-long-string/google/protobuf/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ export const BytesValue = {
};

function bytesFromBase64(b64: string): Uint8Array {
if (globalThis.Buffer) {
if ((globalThis as any).Buffer) {
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
} else {
const bin = globalThis.atob(b64);
Expand Down
2 changes: 1 addition & 1 deletion integration/simple-long/google/protobuf/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ export const BytesValue = {
};

function bytesFromBase64(b64: string): Uint8Array {
if (globalThis.Buffer) {
if ((globalThis as any).Buffer) {
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
} else {
const bin = globalThis.atob(b64);
Expand Down
2 changes: 1 addition & 1 deletion integration/simple-optionals/google/protobuf/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ export const BytesValue = {
};

function bytesFromBase64(b64: string): Uint8Array {
if (globalThis.Buffer) {
if ((globalThis as any).Buffer) {
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
} else {
const bin = globalThis.atob(b64);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ export const BytesValue = {
};

function bytesFromBase64(b64: string): Uint8Array {
if (globalThis.Buffer) {
if ((globalThis as any).Buffer) {
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
} else {
const bin = globalThis.atob(b64);
Expand Down
2 changes: 1 addition & 1 deletion integration/simple-prototype-defaults/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2913,7 +2913,7 @@ interface Rpc {
}

function bytesFromBase64(b64: string): Uint8Array {
if (globalThis.Buffer) {
if ((globalThis as any).Buffer) {
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
} else {
const bin = globalThis.atob(b64);
Expand Down
2 changes: 1 addition & 1 deletion integration/simple-snake/google/protobuf/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ export const BytesValue = {
};

function bytesFromBase64(b64: string): Uint8Array {
if (globalThis.Buffer) {
if ((globalThis as any).Buffer) {
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
} else {
const bin = globalThis.atob(b64);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ export const BytesValue = {
};

function bytesFromBase64(b64: string): Uint8Array {
if (globalThis.Buffer) {
if ((globalThis as any).Buffer) {
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
} else {
const bin = globalThis.atob(b64);
Expand Down
2 changes: 1 addition & 1 deletion integration/simple/google/protobuf/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ export const BytesValue = {
};

function bytesFromBase64(b64: string): Uint8Array {
if (globalThis.Buffer) {
if ((globalThis as any).Buffer) {
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
} else {
const bin = globalThis.atob(b64);
Expand Down
2 changes: 1 addition & 1 deletion integration/simple/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3035,7 +3035,7 @@ interface Rpc {
}

function bytesFromBase64(b64: string): Uint8Array {
if (globalThis.Buffer) {
if ((globalThis as any).Buffer) {
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
} else {
const bin = globalThis.atob(b64);
Expand Down
2 changes: 1 addition & 1 deletion integration/use-map-type/use-map-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ export const Maps_MapOfTimestampsEntry = {
};

function bytesFromBase64(b64: string): Uint8Array {
if (globalThis.Buffer) {
if ((globalThis as any).Buffer) {
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
} else {
const bin = globalThis.atob(b64);
Expand Down
2 changes: 1 addition & 1 deletion integration/use-optionals-all/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ export const Child = {
};

function bytesFromBase64(b64: string): Uint8Array {
if (globalThis.Buffer) {
if ((globalThis as any).Buffer) {
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
} else {
const bin = globalThis.atob(b64);
Expand Down
2 changes: 1 addition & 1 deletion integration/use-optionals-no-undefined/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ export const Child = {
};

function bytesFromBase64(b64: string): Uint8Array {
if (globalThis.Buffer) {
if ((globalThis as any).Buffer) {
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
} else {
const bin = globalThis.atob(b64);
Expand Down
2 changes: 1 addition & 1 deletion integration/value/google/protobuf/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ export const BytesValue = {
};

function bytesFromBase64(b64: string): Uint8Array {
if (globalThis.Buffer) {
if ((globalThis as any).Buffer) {
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
} else {
const bin = globalThis.atob(b64);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ export const BytesValue = {
};

function bytesFromBase64(b64: string): Uint8Array {
if (globalThis.Buffer) {
if ((globalThis as any).Buffer) {
return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
} else {
const bin = globalThis.atob(b64);
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,8 @@ function makeByteUtils(options: Options) {
return bytesFromBase64BrowserSnippet;
default:
return code`
if (${globalThis}.Buffer) {
${bytesFromBase64NodeSnippet}
if ((${globalThis} as any).Buffer) {
${bytesFromBase64NodeSnippet}
} else {
${bytesFromBase64BrowserSnippet}
}
Expand Down

0 comments on commit bae741c

Please sign in to comment.