TypeSpec Mappings
TypeSpec Mappings answer the practical question: when you write a TypeSpec construct, what does Typra generate?
Typra lowers TypeSpec into an internal contract AST before emitting targets. That AST preserves the details needed for runtime loading, saving, provider wire names, generated tests, and review metadata.
| TypeSpec construct | Typra behavior |
|---|---|
| Models and properties | Generate target model surfaces with required, optional, and nested properties. |
| Arrays and records | Generate collection and dictionary-shaped fields using target-appropriate types. |
| String unions | Generate constrained enum-like runtime values, with optional parse aliases. |
| Open unions | Preserve known values while allowing target-specific open string handling. |
| Discriminated models | Generate polymorphic load/save dispatch using the discriminator field. |
| Interfaces and operations | Generate callable protocol/interface/trait-style seams from TypeSpec-native callable contracts. |
| Operation decorators | Add runtime cancellation, sync signatures, optional operations, effect metadata, and vectors to TypeSpec operations. |
| HTTP transport | Project TypeSpec HTTP path, query, header, cookie, body, status, success, and error semantics into producer and consumer seams. |
| Decorators | Add test samples, vectors, wire-name mappings, coercions, factories, defaults, and parse aliases. |
The mapping pages use examples from Typra’s fixture contract so the docs stay aligned with exercised behavior.