Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-rpccompatible-symbol-keys.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"capnweb": patch
---

Fix RpcCompatible type to filter out symbol keys instead of mapping them to never
15 changes: 9 additions & 6 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
// TypeScript uses *structural* typing meaning anything with the same shape as type `T` is a `T`.
// For the classes exported by `cloudflare:workers` we want *nominal* typing (i.e. we only want to
// accept `WorkerEntrypoint` from `cloudflare:workers`, not any other class with the same shape)
export const __RPC_STUB_BRAND: '__RPC_STUB_BRAND';
export const __RPC_TARGET_BRAND: '__RPC_TARGET_BRAND';
export const __RPC_STUB_BRAND: "__RPC_STUB_BRAND";
export const __RPC_TARGET_BRAND: "__RPC_TARGET_BRAND";
export interface RpcTargetBranded {
[__RPC_TARGET_BRAND]: never;
}
Expand All @@ -33,7 +33,9 @@ export type RpcCompatible<T> =
| Array<T extends Array<infer U> ? RpcCompatible<U> : never>
| ReadonlyArray<T extends ReadonlyArray<infer U> ? RpcCompatible<U> : never>
| {
[K in keyof T]: K extends number | string ? RpcCompatible<T[K]> : never;
[K in keyof T as K extends string | number ? K : never]: RpcCompatible<
T[K]
>;
}
| Promise<T extends Promise<infer U> ? RpcCompatible<U> : never>
// Special types
Expand All @@ -48,8 +50,9 @@ interface StubBase<T extends RpcCompatible<T>> extends Disposable {
dup(): this;
onRpcBroken(callback: (error: any) => void): void;
}
export type Stub<T extends RpcCompatible<T>> =
T extends object ? Provider<T> & StubBase<T> : StubBase<T>;
export type Stub<T extends RpcCompatible<T>> = T extends object
? Provider<T> & StubBase<T>
: StubBase<T>;

type TypedArray =
| Uint8Array
Expand Down Expand Up @@ -123,7 +126,7 @@ type UnstubifyInner<T> =

// You can put promises anywhere in the params and they'll be resolved before delivery.
// (This also covers RpcPromise, because it's defined as being a Promise.)
type Unstubify<T> = UnstubifyInner<T> | Promise<UnstubifyInner<T>>
type Unstubify<T> = UnstubifyInner<T> | Promise<UnstubifyInner<T>>;

type UnstubifyAll<A extends any[]> = { [I in keyof A]: Unstubify<A[I]> };

Expand Down
Loading