-
Notifications
You must be signed in to change notification settings - Fork 271
[emitter-framework] Render discriminated unions correctly #7369
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
base: main
Are you sure you want to change the base?
Conversation
All changed packages have been documented.
|
You can try these changes here
|
packages/emitter-framework/test/typescript/components/union-declaration.test.tsx
Show resolved
Hide resolved
|
||
const [namespace] = program.resolveTypeReference("DemoService"); | ||
const union = Array.from((namespace as Namespace).enums.values())[0]; | ||
it("renders a discriminated union declaration with no envelope", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does it looks like in thoses cases when you use a named model?
}, | ||
}); | ||
|
||
return <TypeExpression type={model} />; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a better type might be to create a typescript intersection here for each variant.
type Pet = {kind: "a"} & Cat | {kind: "b"} & Dog
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or at least if the model has a name
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:
ObjectEnvelope
andNoneEnvelope
functions inunion-expression.tsx
. These handle different discriminator configurations and ensure proper rendering of union variants. [1] [2]Updates to existing components:
InterfaceBody
component ininterface-declaration.tsx
to include a semicolon when rendering type members, ensuring consistency with TypeScript syntax. Found in passing and validated via the new testsImprovements to test coverage:
union-declaration.test.tsx
using the new testing patternsFixes #7174