Skip to content

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 constructTypra behavior
Models and propertiesGenerate target model surfaces with required, optional, and nested properties.
Arrays and recordsGenerate collection and dictionary-shaped fields using target-appropriate types.
String unionsGenerate constrained enum-like runtime values, with optional parse aliases.
Open unionsPreserve known values while allowing target-specific open string handling.
Discriminated modelsGenerate polymorphic load/save dispatch using the discriminator field.
Interfaces and operationsGenerate callable protocol/interface/trait-style seams from TypeSpec-native callable contracts.
Operation decoratorsAdd runtime cancellation, sync signatures, optional operations, effect metadata, and vectors to TypeSpec operations.
HTTP transportProject TypeSpec HTTP path, query, header, cookie, body, status, success, and error semantics into producer and consumer seams.
DecoratorsAdd 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.