Dispatch declaration overrides in Experimental_ComponentOverrides - #11597
Dispatch declaration overrides in Experimental_ComponentOverrides#11597Timothee Guerin (timotheeguerin) wants to merge 2 commits into
Conversation
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.
…al_ComponentOverrides The `declaration` descriptor existed but nothing dispatched to it, so an emitter could override how a type is referenced but not how it is declared. The C# `ClassDeclaration`, `Property` and `EnumDeclaration` now render through the override point.
commit: |
|
All changed packages have been documented.
Show changes
|
|
You can try these changes here
|
An override descriptor already accepted a
declarationentry, but nothing ever dispatched to it — onlyreferencewas wired up. So an emitter could change how a type is referenced and had no say in how it is declared. The only way to customize a declaration was to copy the framework component into your own package and diverge from it, which is exactly what@typespec/http-server-csharpdid for classes, properties and enums.Experimental_OverridableComponentnow dispatchesdeclarationtoo, and the C#ClassDeclaration,PropertyandEnumDeclarationrender through it. An override can replace the declaration outright, or re-render the default with different props:props.Declarationis the unwrapped body, so re-rendering it does not recurse back through the override.The declaration props type is generic and defaults to
Record<string, any>, because the existingExperimental_CustomTypeToPropsmap is TypeScript-specific (VarDeclarationProps,ObjectPropertyProps) and means nothing for C#. Callers that want type safety pass the concrete props type:.forTypeKind<"ModelProperty", PropertyProps>(...).Part of a 7-PR stack moving
@typespec/http-server-csharponto the emitter framework. Stacked on #11596 — only the last commit is new here.