From b95dfee5a47a28d58bf56ca08c1ad12f076e3903 Mon Sep 17 00:00:00 2001 From: Doug Clark Date: Mon, 4 Apr 2022 14:29:56 -0700 Subject: [PATCH 1/2] Use Uint8Array.forEach in base64FromBytes Otherwise, TypeScript 4.6.2 complains: TS2569: Type 'Uint8Array' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators. 184 | function base64FromBytes(arr: Uint8Array): string { 185 | const bin: string[] = []; > 186 | for (const byte of arr) { | ^^^ --- src/main.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.ts b/src/main.ts index a12c03764..0a6ac160f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -423,9 +423,9 @@ function makeByteUtils() { const btoa : (bin: string) => string = ${globalThis}.btoa || ((bin) => ${globalThis}.Buffer.from(bin, 'binary').toString('base64')); function base64FromBytes(arr: Uint8Array): string { const bin: string[] = []; - for (const byte of arr) { + arr.forEach((byte) => { bin.push(String.fromCharCode(byte)); - } + }); return btoa(bin.join('')); } ` From b6435c8be71d86e691c49f1176d30b5be274d0b0 Mon Sep 17 00:00:00 2001 From: Doug Clark Date: Fri, 8 Apr 2022 14:02:01 -0700 Subject: [PATCH 2/2] Update integration test generated code. --- integration/bytes-as-base64/message.ts | 4 ++-- integration/bytes-node/google/protobuf/wrappers.ts | 4 ++-- integration/bytes-node/point.ts | 4 ++-- integration/grpc-js/google/protobuf/wrappers.ts | 4 ++-- integration/oneof-properties/oneof.ts | 4 ++-- integration/oneof-unions/oneof.ts | 4 ++-- integration/simple-long-string/google/protobuf/wrappers.ts | 4 ++-- integration/simple-long/google/protobuf/wrappers.ts | 4 ++-- integration/simple-optionals/google/protobuf/wrappers.ts | 4 ++-- .../simple-prototype-defaults/google/protobuf/wrappers.ts | 4 ++-- integration/simple-prototype-defaults/simple.ts | 4 ++-- integration/simple-snake/google/protobuf/wrappers.ts | 4 ++-- .../simple-unrecognized-enum/google/protobuf/wrappers.ts | 4 ++-- integration/simple/google/protobuf/wrappers.ts | 4 ++-- integration/simple/simple.ts | 4 ++-- integration/use-optionals-all/test.ts | 4 ++-- integration/value/google/protobuf/wrappers.ts | 4 ++-- 17 files changed, 34 insertions(+), 34 deletions(-) diff --git a/integration/bytes-as-base64/message.ts b/integration/bytes-as-base64/message.ts index b67cba7a5..8a3e0e8fc 100644 --- a/integration/bytes-as-base64/message.ts +++ b/integration/bytes-as-base64/message.ts @@ -59,9 +59,9 @@ const btoa: (bin: string) => string = globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64')); function base64FromBytes(arr: Uint8Array): string { const bin: string[] = []; - for (const byte of arr) { + arr.forEach((byte) => { bin.push(String.fromCharCode(byte)); - } + }); return btoa(bin.join('')); } diff --git a/integration/bytes-node/google/protobuf/wrappers.ts b/integration/bytes-node/google/protobuf/wrappers.ts index 112ffd658..892e6f8bb 100644 --- a/integration/bytes-node/google/protobuf/wrappers.ts +++ b/integration/bytes-node/google/protobuf/wrappers.ts @@ -562,9 +562,9 @@ const btoa: (bin: string) => string = globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64')); function base64FromBytes(arr: Uint8Array): string { const bin: string[] = []; - for (const byte of arr) { + arr.forEach((byte) => { bin.push(String.fromCharCode(byte)); - } + }); return btoa(bin.join('')); } diff --git a/integration/bytes-node/point.ts b/integration/bytes-node/point.ts index 46182189c..ed60534a1 100644 --- a/integration/bytes-node/point.ts +++ b/integration/bytes-node/point.ts @@ -95,9 +95,9 @@ const btoa: (bin: string) => string = globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64')); function base64FromBytes(arr: Uint8Array): string { const bin: string[] = []; - for (const byte of arr) { + arr.forEach((byte) => { bin.push(String.fromCharCode(byte)); - } + }); return btoa(bin.join('')); } diff --git a/integration/grpc-js/google/protobuf/wrappers.ts b/integration/grpc-js/google/protobuf/wrappers.ts index 7b431a98d..04a56043a 100644 --- a/integration/grpc-js/google/protobuf/wrappers.ts +++ b/integration/grpc-js/google/protobuf/wrappers.ts @@ -562,9 +562,9 @@ const btoa: (bin: string) => string = globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64')); function base64FromBytes(arr: Uint8Array): string { const bin: string[] = []; - for (const byte of arr) { + arr.forEach((byte) => { bin.push(String.fromCharCode(byte)); - } + }); return btoa(bin.join('')); } diff --git a/integration/oneof-properties/oneof.ts b/integration/oneof-properties/oneof.ts index bcf0f1e54..d937ae5e5 100644 --- a/integration/oneof-properties/oneof.ts +++ b/integration/oneof-properties/oneof.ts @@ -304,9 +304,9 @@ const btoa: (bin: string) => string = globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64')); function base64FromBytes(arr: Uint8Array): string { const bin: string[] = []; - for (const byte of arr) { + arr.forEach((byte) => { bin.push(String.fromCharCode(byte)); - } + }); return btoa(bin.join('')); } diff --git a/integration/oneof-unions/oneof.ts b/integration/oneof-unions/oneof.ts index 01d12954c..c76d68a4d 100644 --- a/integration/oneof-unions/oneof.ts +++ b/integration/oneof-unions/oneof.ts @@ -412,9 +412,9 @@ const btoa: (bin: string) => string = globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64')); function base64FromBytes(arr: Uint8Array): string { const bin: string[] = []; - for (const byte of arr) { + arr.forEach((byte) => { bin.push(String.fromCharCode(byte)); - } + }); return btoa(bin.join('')); } diff --git a/integration/simple-long-string/google/protobuf/wrappers.ts b/integration/simple-long-string/google/protobuf/wrappers.ts index f3633c134..2dcb80081 100644 --- a/integration/simple-long-string/google/protobuf/wrappers.ts +++ b/integration/simple-long-string/google/protobuf/wrappers.ts @@ -562,9 +562,9 @@ const btoa: (bin: string) => string = globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64')); function base64FromBytes(arr: Uint8Array): string { const bin: string[] = []; - for (const byte of arr) { + arr.forEach((byte) => { bin.push(String.fromCharCode(byte)); - } + }); return btoa(bin.join('')); } diff --git a/integration/simple-long/google/protobuf/wrappers.ts b/integration/simple-long/google/protobuf/wrappers.ts index 59553b565..791fdbc7b 100644 --- a/integration/simple-long/google/protobuf/wrappers.ts +++ b/integration/simple-long/google/protobuf/wrappers.ts @@ -562,9 +562,9 @@ const btoa: (bin: string) => string = globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64')); function base64FromBytes(arr: Uint8Array): string { const bin: string[] = []; - for (const byte of arr) { + arr.forEach((byte) => { bin.push(String.fromCharCode(byte)); - } + }); return btoa(bin.join('')); } diff --git a/integration/simple-optionals/google/protobuf/wrappers.ts b/integration/simple-optionals/google/protobuf/wrappers.ts index 7b431a98d..04a56043a 100644 --- a/integration/simple-optionals/google/protobuf/wrappers.ts +++ b/integration/simple-optionals/google/protobuf/wrappers.ts @@ -562,9 +562,9 @@ const btoa: (bin: string) => string = globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64')); function base64FromBytes(arr: Uint8Array): string { const bin: string[] = []; - for (const byte of arr) { + arr.forEach((byte) => { bin.push(String.fromCharCode(byte)); - } + }); return btoa(bin.join('')); } diff --git a/integration/simple-prototype-defaults/google/protobuf/wrappers.ts b/integration/simple-prototype-defaults/google/protobuf/wrappers.ts index 9176a870b..7e974d6b0 100644 --- a/integration/simple-prototype-defaults/google/protobuf/wrappers.ts +++ b/integration/simple-prototype-defaults/google/protobuf/wrappers.ts @@ -562,9 +562,9 @@ const btoa: (bin: string) => string = globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64')); function base64FromBytes(arr: Uint8Array): string { const bin: string[] = []; - for (const byte of arr) { + arr.forEach((byte) => { bin.push(String.fromCharCode(byte)); - } + }); return btoa(bin.join('')); } diff --git a/integration/simple-prototype-defaults/simple.ts b/integration/simple-prototype-defaults/simple.ts index 50983e3a3..d1f431dfb 100644 --- a/integration/simple-prototype-defaults/simple.ts +++ b/integration/simple-prototype-defaults/simple.ts @@ -2369,9 +2369,9 @@ const btoa: (bin: string) => string = globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64')); function base64FromBytes(arr: Uint8Array): string { const bin: string[] = []; - for (const byte of arr) { + arr.forEach((byte) => { bin.push(String.fromCharCode(byte)); - } + }); return btoa(bin.join('')); } diff --git a/integration/simple-snake/google/protobuf/wrappers.ts b/integration/simple-snake/google/protobuf/wrappers.ts index 7b431a98d..04a56043a 100644 --- a/integration/simple-snake/google/protobuf/wrappers.ts +++ b/integration/simple-snake/google/protobuf/wrappers.ts @@ -562,9 +562,9 @@ const btoa: (bin: string) => string = globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64')); function base64FromBytes(arr: Uint8Array): string { const bin: string[] = []; - for (const byte of arr) { + arr.forEach((byte) => { bin.push(String.fromCharCode(byte)); - } + }); return btoa(bin.join('')); } diff --git a/integration/simple-unrecognized-enum/google/protobuf/wrappers.ts b/integration/simple-unrecognized-enum/google/protobuf/wrappers.ts index 7b431a98d..04a56043a 100644 --- a/integration/simple-unrecognized-enum/google/protobuf/wrappers.ts +++ b/integration/simple-unrecognized-enum/google/protobuf/wrappers.ts @@ -562,9 +562,9 @@ const btoa: (bin: string) => string = globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64')); function base64FromBytes(arr: Uint8Array): string { const bin: string[] = []; - for (const byte of arr) { + arr.forEach((byte) => { bin.push(String.fromCharCode(byte)); - } + }); return btoa(bin.join('')); } diff --git a/integration/simple/google/protobuf/wrappers.ts b/integration/simple/google/protobuf/wrappers.ts index 7b431a98d..04a56043a 100644 --- a/integration/simple/google/protobuf/wrappers.ts +++ b/integration/simple/google/protobuf/wrappers.ts @@ -562,9 +562,9 @@ const btoa: (bin: string) => string = globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64')); function base64FromBytes(arr: Uint8Array): string { const bin: string[] = []; - for (const byte of arr) { + arr.forEach((byte) => { bin.push(String.fromCharCode(byte)); - } + }); return btoa(bin.join('')); } diff --git a/integration/simple/simple.ts b/integration/simple/simple.ts index a9a321e3d..278506635 100644 --- a/integration/simple/simple.ts +++ b/integration/simple/simple.ts @@ -2357,9 +2357,9 @@ const btoa: (bin: string) => string = globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64')); function base64FromBytes(arr: Uint8Array): string { const bin: string[] = []; - for (const byte of arr) { + arr.forEach((byte) => { bin.push(String.fromCharCode(byte)); - } + }); return btoa(bin.join('')); } diff --git a/integration/use-optionals-all/test.ts b/integration/use-optionals-all/test.ts index e2d815cb8..396e4ccd7 100644 --- a/integration/use-optionals-all/test.ts +++ b/integration/use-optionals-all/test.ts @@ -563,9 +563,9 @@ const btoa: (bin: string) => string = globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64')); function base64FromBytes(arr: Uint8Array): string { const bin: string[] = []; - for (const byte of arr) { + arr.forEach((byte) => { bin.push(String.fromCharCode(byte)); - } + }); return btoa(bin.join('')); } diff --git a/integration/value/google/protobuf/wrappers.ts b/integration/value/google/protobuf/wrappers.ts index 7b431a98d..04a56043a 100644 --- a/integration/value/google/protobuf/wrappers.ts +++ b/integration/value/google/protobuf/wrappers.ts @@ -562,9 +562,9 @@ const btoa: (bin: string) => string = globalThis.btoa || ((bin) => globalThis.Buffer.from(bin, 'binary').toString('base64')); function base64FromBytes(arr: Uint8Array): string { const bin: string[] = []; - for (const byte of arr) { + arr.forEach((byte) => { bin.push(String.fromCharCode(byte)); - } + }); return btoa(bin.join('')); }