Skip to content

Commit 189fa79

Browse files
authored
Fix type overrides for Uint8Array's toBase64 and fromBase64 leaking into capnweb's public interface. (#148)
These type overrides were meant for type-checking Cap'n Web's own code, but the TS compiler "helpfully" shlepped them into the public `index.d.ts` for the capnweb package, affecting dependent builds. Oops!
1 parent 03c82e8 commit 189fa79

4 files changed

Lines changed: 36 additions & 19 deletions

File tree

.changeset/fluffy-masks-draw.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"capnweb": patch
3+
---
4+
5+
Fixed type overrides for Uint8Array's toBase64 and fromBase64 leaking into capnweb's public interface.

__type-tests__/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
"compilerOptions": {
44
"noEmit": true
55
},
6-
"include": ["./**/*.ts"]
6+
"include": ["./**/*.ts", "../src/base64-shims.d.ts"]
77
}

src/base64-shims.d.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) 2026 Cloudflare, Inc.
2+
// Licensed under the MIT license found in the LICENSE.txt file or at:
3+
// https://opensource.org/license/mit
4+
5+
// Polyfill types for Uint8Array.toBase64() / Uint8Array.fromBase64(), which have started landing
6+
// in JS runtimes but are not supported everywhere just yet.
7+
//
8+
// This file is intentionally not imported by any source file. It is picked up by tsconfig.json's
9+
// include glob for our own compilation, but excluded from the published declaration bundle (which
10+
// only traces the import graph from entry points). This avoids leaking the optional toBase64 /
11+
// fromBase64 declarations into consumers' global types.
12+
13+
declare global {
14+
interface Uint8Array {
15+
toBase64?(options?: {
16+
alphabet?: "base64" | "base64url",
17+
omitPadding?: boolean
18+
}): string;
19+
}
20+
21+
interface Uint8ArrayConstructor {
22+
fromBase64?(text: string, options?: {
23+
alphabet?: "base64" | "base64url",
24+
lastChunkHandling?: "loose" | "strict" | "stop-before-partial"
25+
}): Uint8Array;
26+
}
27+
}
28+
29+
// mark this file as a module so augmentation works correctly
30+
export {};

src/serialize.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,6 @@ const ERROR_TYPES: Record<string, any> = {
5252
// TODO: DOMError? Others?
5353
};
5454

55-
// Polyfill types for Uint8Array.toBase64() / Uint8Array.fromBase64(), which have started landing
56-
// in JS runtimes but are not supported everywhere just yet.
57-
declare global {
58-
interface Uint8Array {
59-
toBase64?(options?: {
60-
alphabet?: "base64" | "base64url",
61-
omitPadding?: boolean
62-
}): string;
63-
}
64-
65-
interface Uint8ArrayConstructor {
66-
fromBase64?(text: string, options?: {
67-
alphabet?: "base64" | "base64url",
68-
lastChunkHandling?: "loose" | "strict" | "stop-before-partial"
69-
}): Uint8Array;
70-
}
71-
}
72-
7355
// Converts fully-hydrated messages into object trees that are JSON-serializable for sending over
7456
// the wire. This is used to implement serialization -- but it doesn't take the last step of
7557
// actually converting to a string. (The name is meant to be the opposite of "Evaluator", which

0 commit comments

Comments
 (0)