Skip to content

Make the C# TypeExpression handle every type kind - #11596

Draft
Timothee Guerin (timotheeguerin) wants to merge 1 commit into
microsoft:mainfrom
timotheeguerin:ef/csharp-type-expression-total
Draft

Make the C# TypeExpression handle every type kind#11596
Timothee Guerin (timotheeguerin) wants to merge 1 commit into
microsoft:mainfrom
timotheeguerin:ef/csharp-type-expression-total

Conversation

@timotheeguerin

Copy link
Copy Markdown
Member

The C# TypeExpression threw a hard Error for anything it did not recognise — tuples, string templates, enum members, template parameters and most of the intrinsics. An emitter hitting one of those got a crash with no source location instead of a diagnostic, so @typespec/http-server-csharp had to wrap every call site in try/catch.

Those kinds are now handled, and a genuinely unsupported type reports a diagnostic against the offending type and falls back to object, so compilation continues and the user gets a pointer to the spec that caused it.

Two smaller bugs fixed along the way:

  • Unsupported scalars reported a TypeScript diagnostic (typescript-unsupported-scalar) from the C# components.
  • The null and never intrinsics emitted null and never, neither of which is a C# type. They now emit object and void.

Also adds an isCSharpValueType util, since deciding whether a TypeSpec type maps to a C# struct is something every C# emitter needs and every C# emitter was reimplementing.


First of a 7-PR stack that moves @typespec/http-server-csharp onto the emitter framework instead of its private forks. Nothing depends on this one; it can merge on its own.

Adds handling for Tuple, StringTemplate, EnumMember, ModelProperty, UnionVariant,
template parameters and the full Intrinsic set. An unsupported type now reports a
diagnostic and falls back to `object` instead of throwing.

Also fixes the C# components reporting a TypeScript diagnostic for unsupported
scalars, and corrects the C# expressions emitted for the `null` and `never`
intrinsics. Adds an `isCSharpValueType` util.
@pkg-pr-new

pkg-pr-new Bot commented Aug 7, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/emitter-framework@11596

commit: 1071e34

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/emitter-framework
Show changes

@typespec/emitter-framework - fix ✏️

Make the C# TypeExpression handle every type kind instead of throwing,> ,> Tuple, StringTemplate, EnumMember, ModelProperty, UnionVariant, template parameters and the full Intrinsic set are now supported, and an unsupported type reports a diagnostic and falls back to object rather than throwing. Also fixes the C# components reporting a TypeScript diagnostic for unsupported scalars, and corrects the C# expressions for the null and never intrinsics.

@azure-sdk-automation

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

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

Labels

emitter-framework Issues for the emitter framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant