Skip to content

[http-client-csharp] Preserve enum type when @alternateType collapses single-member enum to constant#10281

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-enum-type-collapsing-issue
Draft

[http-client-csharp] Preserve enum type when @alternateType collapses single-member enum to constant#10281
Copilot wants to merge 3 commits intomainfrom
copilot/fix-enum-type-collapsing-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 7, 2026

When @alternateType("green") is applied to a required property of type Colors (a single-member enum), TCGC resolves it as an SdkConstantType instead of SdkEnumType. The emitter's case "constant": branch only promoted constants to extensible enums for optional/nullable properties, so required properties collapsed to string literals.

Changes

  • emitter/src/lib/type-converter.ts: In the case "constant": branch, check sdkProperty.__raw?.type?.kind === "Enum" to detect when the original TypeSpec property type was an enum. When true, convert to extensible enum regardless of optionality.
  • emitter/test/Unit/constant-type.test.ts: Added test for single-member enum with @alternateType on a required property, asserting kind === "enum" and isFixed === false.

Repro

enum Colors { green }

model EmployeeProperties {
  @Azure.ClientGenerator.Core.alternateType("green")
  favoriteColor: Colors;
}

Before: favoriteColor emitted as constant "green"
After: favoriteColor emitted as extensible enum type

…num to constant

Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/f1259764-9aff-4b82-87b9-341ba62673a2

Co-authored-by: live1206 <5196139+live1206@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label Apr 7, 2026
Copilot AI changed the title [WIP] Fix single-member enum collapsing to constant instead of preserving type [http-client-csharp] Preserve enum type when @alternateType collapses single-member enum to constant Apr 7, 2026
Copilot AI requested a review from live1206 April 7, 2026 09:48
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 7, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-csharp@10281

commit: 67380b3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[http-client-csharp] Single-member enum with @alternateType incorrectly collapses to constant instead of preserving enum type

2 participants