Skip to content

Commit bdbfa9a

Browse files
byseif21Copilot
andauthored
chore: resolve Uint8Array.prototype.toHex TypeScript error (@byseif21) (#7711)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 4c53bce commit bdbfa9a

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

frontend/src/ts/utils/strings.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,17 @@ export function areCharactersVisuallyEqual(
320320
}
321321

322322
export function toHex(buffer: ArrayBuffer): string {
323-
if (Uint8Array.prototype.toHex !== undefined) {
324-
return new Uint8Array(buffer).toHex();
323+
const u8 = new Uint8Array(buffer);
324+
325+
// Use native toHex if available (modern browsers / future runtimes)
326+
if (
327+
"toHex" in u8 &&
328+
typeof (u8 as { toHex?: unknown }).toHex === "function"
329+
) {
330+
return (u8 as unknown as { toHex(): string }).toHex();
325331
}
326-
const hashArray = Array.from(new Uint8Array(buffer));
332+
333+
const hashArray = Array.from(u8);
327334
const hashHex = hashArray
328335
.map((b) => b.toString(16).padStart(2, "0"))
329336
.join("");

0 commit comments

Comments
 (0)