fix(types): filter symbol keys in Rpc.Serializable mapped type#5804
fix(types): filter symbol keys in Rpc.Serializable mapped type#5804dmmulroy wants to merge 3 commits intocloudflare:mainfrom
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
CodSpeed Performance ReportMerging this PR will degrade performance by 18.5%Comparing Summary
Performance Changes
Footnotes
|
kentonv
left a comment
There was a problem hiding this comment.
Should we update https://github.com/cloudflare/capnweb/blob/main/src/types.d.ts as well?
| | ReadonlyArray<T extends ReadonlyArray<infer U> ? Serializable<U> : never> | ||
| | { | ||
| [K in keyof T]: K extends number | string ? Serializable<T[K]> : never; | ||
| [K in keyof T as K extends string | number ? K : never]: Serializable<T[K]>; |
There was a problem hiding this comment.
1d76250 to
ba5158f
Compare
dario-piotrowicz
left a comment
There was a problem hiding this comment.
Looks good to me 🙂
But possibly as Kenton mentioned there might be other places where this should be applied
Use key remapping to filter out symbol keys instead of mapping to never. Fixes Disposable compatibility issue with RPC types. Ref: cloudflare/workerd#5804
|
capnweb updated: cloudflare/capnweb#129 |
ba5158f to
9cb7813
Compare
Use key remapping to filter out symbol keys instead of mapping to never. Fixes Disposable compatibility issue with RPC types. Ref: cloudflare/workerd#5804
Use key remapping to filter out symbol keys instead of mapping to never. Fixes Disposable compatibility issue with RPC types. Ref: cloudflare/workerd#5804
Use key remapping to filter out symbol keys instead of mapping to never. Fixes Disposable compatibility issue with RPC types. Ref: cloudflare/workerd#5804
|
@dmmulroy it looks like this is pretty red in CI |
d03921d to
2adfbc0
Compare
- Remove failing nonSerializable test assertions that expected 'never' (ReadableStream<string> matches the object branch of Serializable<T>) - Update generated type snapshots with the new Serializable mapped type
2adfbc0 to
5eb0216
Compare
| // Note: ReadableStream<string> and objects containing it are matched by | ||
| // the object branch of Serializable<T> since they have string-keyed properties. | ||
| // The type system cannot distinguish between "intentionally serializable objects" | ||
| // and "built-in objects that happen to have string keys", so these are not | ||
| // rejected at the type level (though they would fail at runtime). |
There was a problem hiding this comment.
I'm not sure about this test change...
Problem
Rpc.Serializable<T>fails to match valid serializable types when they include symbol keys (e.g.,Symbol.disposefromDisposable).When using
WorkflowStep.do()with a Durable Object stub return value:TypeScript errors:
Reproduction
https://github.com/dmmulroy/workerd-rpc-serializable-type-repro
Cause
The mapped type uses a value-side conditional that maps symbol keys to
neverinstead of filtering them out:This creates an object type that has the symbol keys but with
nevervalues, causing assignability failures.Fix
Use key remapping with
asclause to filter out non-string/number keys entirely:{ - [K in keyof T]: K extends number | string ? Serializable<T[K]> : never; + [K in keyof T as K extends string | number ? K : never]: Serializable<T[K]>; }Safety & Backwards Compatibility
This change is safe because:
Note
This PR was written with AI assistance.
AI Session Export