Skip to content

[emitter-framework] Render discriminated unions correctly #7369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
May 20, 2025

Conversation

maorleger
Copy link
Member

@maorleger maorleger commented May 15, 2025

This pull request enhances the handling of discriminated unions in the @typespec/emitter-framework package. It introduces new rendering logic for discriminated unions, updates existing components to support these changes, and improves test coverage to validate the new functionality.

Enhancements to discriminated union rendering:

  • Added new rendering logic for discriminated unions, including support for "object" and "none" envelope styles, through the ObjectEnvelope and NoneEnvelope functions in union-expression.tsx. These handle different discriminator configurations and ensure proper rendering of union variants. [1] [2]

Updates to existing components:

  • Modified the InterfaceBody component in interface-declaration.tsx to include a semicolon when rendering type members, ensuring consistency with TypeScript syntax. Found in passing and validated via the new tests

Improvements to test coverage:

  • Refactored and expanded tests in union-declaration.test.tsx using the new testing patterns

Fixes #7174

Copy link
Contributor

github-actions bot commented May 15, 2025

All changed packages have been documented.

  • @typespec/emitter-framework
Show changes

@typespec/emitter-framework - fix ✏️

Render discriminated unions correctly

@azure-sdk
Copy link
Collaborator

azure-sdk commented May 15, 2025

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

@maorleger maorleger marked this pull request as ready for review May 15, 2025 22:14
@maorleger maorleger requested a review from joheredi May 19, 2025 14:26
@maorleger maorleger added this pull request to the merge queue May 20, 2025
Merged via the queue into microsoft:main with commit 2c185d5 May 20, 2025
24 checks passed
@maorleger maorleger deleted the discriminated-union-ef branch May 20, 2025 21:15
ArcturusZhang pushed a commit to ArcturusZhang/typespec that referenced this pull request May 21, 2025
…7369)

This pull request enhances the handling of discriminated unions in the
`@typespec/emitter-framework` package. It introduces new rendering logic
for discriminated unions, updates existing components to support these
changes, and improves test coverage to validate the new functionality.

### Enhancements to discriminated union rendering:

* Added new rendering logic for discriminated unions, including support
for "object" and "none" envelope styles, through the `ObjectEnvelope`
and `NoneEnvelope` functions in `union-expression.tsx`. These handle
different discriminator configurations and ensure proper rendering of
union variants.
[[1]](diffhunk://#diff-400029c681b8e2281a1bde7777af749a18d635dcf9ddaa4a6c9cb1bd86301fe7L22-R27)
[[2]](diffhunk://#diff-400029c681b8e2281a1bde7777af749a18d635dcf9ddaa4a6c9cb1bd86301fe7R38-R127)

### Updates to existing components:

* Modified the `InterfaceBody` component in `interface-declaration.tsx`
to include a semicolon when rendering type members, ensuring consistency
with TypeScript syntax. Found in passing and validated via the new tests


### Improvements to test coverage:

* Refactored and expanded tests in `union-declaration.test.tsx` using
the new testing patterns

Fixes microsoft#7174
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: TypeScript Emitter Framework does not handle new discriminated unions
4 participants