diff --git a/.changeset/fix-rpccompatible-symbol-keys.md b/.changeset/fix-rpccompatible-symbol-keys.md new file mode 100644 index 0000000..0b9bbf8 --- /dev/null +++ b/.changeset/fix-rpccompatible-symbol-keys.md @@ -0,0 +1,5 @@ +--- +"capnweb": patch +--- + +Fix RpcCompatible type to filter out symbol keys instead of mapping them to never diff --git a/src/types.d.ts b/src/types.d.ts index c5a2897..2d00d96 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -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; } @@ -33,7 +33,9 @@ export type RpcCompatible = | Array ? RpcCompatible : never> | ReadonlyArray ? RpcCompatible : never> | { - [K in keyof T]: K extends number | string ? RpcCompatible : never; + [K in keyof T as K extends string | number ? K : never]: RpcCompatible< + T[K] + >; } | Promise ? RpcCompatible : never> // Special types @@ -48,8 +50,9 @@ interface StubBase> extends Disposable { dup(): this; onRpcBroken(callback: (error: any) => void): void; } -export type Stub> = - T extends object ? Provider & StubBase : StubBase; +export type Stub> = T extends object + ? Provider & StubBase + : StubBase; type TypedArray = | Uint8Array @@ -123,7 +126,7 @@ type UnstubifyInner = // 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 = UnstubifyInner | Promise> +type Unstubify = UnstubifyInner | Promise>; type UnstubifyAll = { [I in keyof A]: Unstubify };