Support async chaining in TypeScript AppHosts#17400
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 17400Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 17400" |
There was a problem hiding this comment.
Pull request overview
Updates the TypeScript ATS code generator so generated async members that return chainable wrapper types expose a thenable (PromiseLike) surface, enabling fluent chaining with a single await across wrapper-returning methods and getter-style async members (including callback/context APIs). The TypeScript validation AppHost is updated to exercise the intended chaining syntax.
Changes:
- Extend TypeScript generation to emit
*Promiseinterfaces/classes for wrapper-returning async methods and getter-style async members. - Update the TypeScript validation AppHost to use single-
awaitfluent chaining patterns. - Refresh TypeScript codegen snapshot baselines to match the new generated API shapes.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tests/PolyglotAppHosts/Aspire.Hosting/TypeScript/apphost.mts | Adjusts validation script to use single-await chaining through generated thenable wrapper APIs. |
| tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/TwoPassScanningGeneratedAspire.verified.ts | Updates two-pass scanning snapshot to include generated thenable wrapper return types and promise wrapper types. |
| tests/Aspire.Hosting.CodeGeneration.TypeScript.Tests/Snapshots/AtsGeneratedAspire.verified.ts | Updates ATS snapshot to include new *Promise wrapper types (e.g., for getter-style members). |
| src/Aspire.Hosting.CodeGeneration.TypeScript/AtsTypeScriptCodeGenerator.cs | Implements generator changes to emit thenable promise wrapper return types for chainable wrapper-returning async members and getter-only async members. |
|
❓ CLI E2E Tests unknown — 96 passed, 0 failed, 5 unknown (commit View all recordings
📹 Recordings uploaded automatically from CI run #26319344193 |
JamesNK
left a comment
There was a problem hiding this comment.
Looks good. The promise wrapper generation is correct and consistent across all code paths (builder methods, context methods, wrapper methods, property objects, and thenable wrappers). The track parameter usage follows the existing convention, and the thenable unwrapping semantics are sound.
Documents the async chaining feature introduced in microsoft/aspire#17400. TypeScript AppHosts can now chain through generated async methods that return wrapper types with a single await, using the new PromiseLike thenable wrapper pattern emitted by the code generator. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Pull request created: #1056
|
|
📝 Documentation has been drafted in microsoft/aspire.dev#1056 targeting Added an "Async chaining" section to Note This draft PR needs human review before merging. |
Description
TypeScript AppHost APIs already support fluent chaining for builder methods like
builder.addContainer(...).withReference(...), but generated async methods that returned other generated wrapper types still required callers to split the chain or use a double await. This updates TypeScript code generation so any generated async method returning a chainable wrapper type exposes the same thenable surface.The generator now emits promise wrapper return types for wrapper-returning generated async methods and getter-style generated async members, including callback/context APIs. The TypeScript validation AppHost covers the intended syntax instead of asserting generated code shape directly.
User-facing usage
TypeScript AppHosts can now chain through generated async methods with a single await:
Fixes # (issue)
Checklist
<remarks />and<code />elements on your triple slash comments?