chore(pass-style): only Promise<Passable> is passable#3068
chore(pass-style): only Promise<Passable> is passable#3068michaelfig wants to merge 3 commits intomfig/readonly-array-is-passablefrom
Promise<Passable> is passable#3068Conversation
There was a problem hiding this comment.
Pull request overview
This PR strengthens TypeScript type safety for passable promises by constraining them to only accept Promise<Passable> instead of Promise<any>. This prevents promises that will likely fulfill to non-passable values from being accepted at compile time.
Changes:
- Updated type definitions to require promises to be
Promise<Passable>instead ofPromise<any> - Simplified
PassByReftype to use a singlePromise<Passable>instead of multiple specific promise types - Made
AwaitedPassableCapan internal type since it's only used within the type definitions - Added test annotations to validate the new type constraints
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/pass-style/src/types.d.ts | Tightened promise types from Promise<any> to Promise<Passable> across PassByRef, PassStyleOf, and PassableCap; made AwaitedPassableCap internal |
| packages/pass-style/src/types.test-d.ts | Added @ts-expect-error annotations to verify promises of non-passable values are correctly rejected by the type system |
| packages/pass-style/NEWS.md | Documented the type changes and their purpose |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
9820996 to
63188ce
Compare
63188ce to
7de5605
Compare
|
I have tried to do this before (taking over an attempt from @turadg), and things broke horribly in agoric-sdk (Agoric/agoric-sdk#9943) |
|
I'd love to see this tightened up. But per what Mathieu pointed out, I'm requesting that the test plan include a green integration branch with agoric-sdk. (IMO that can use ts-expect-error and other escape hatches so we can correct Endo and catch in in agoric-sdk over time.) |
Description
This PR strengthens TypeScript type safety for passable promises by requiring them to accept only
Promise<Passable>rather thanPromise<any>. This prevents promises that will likely fulfill to non-passable values from being accepted at compile time.Changes:
AwaitedPassabletype, which only includes the non-Promise branches of the existingPassableunion type.Passabletype to beAwaitedPassable | Promise<AwaitedPassable>to break infinite promise expansion.PassByReftype to use a singlePromise<Passable>instead of multiple specific promise typesAwaitedPassableCaptype, which only includes the non-Promise branches of the existingPassableCapunion type.PassableCaptype to beAwaitedPassableCap | Promise<Passable>instead of... | Promise<any>.Security Considerations
Guardrails only. By design, the TypeScript programming language provides pragmatic but unsound types.
Scaling Considerations
n/a
Documentation Considerations
Documented in
NEWS.md, but should be intuitive enough, and can always be@ts-expect-errorred if it gets in the way.Testing Considerations
CI, and
types.test-d.tslinting.Compatibility Considerations
Should not break naïve code, only code that is really doing something dodgy.
Upgrade Considerations
Types only. No effect on runtime execution.