Skip to content

Collections and records

Typra preserves the collection shape from TypeSpec and lets each target choose the idiomatic runtime type.

model FixtureRoot {
tags: string[];
metadata?: Record<unknown>;
contentItems: FixtureContent[];
}
TypeSpecTypra mapping
string[]Array or list of scalar values.
FixtureContent[]Array or list of nested model values, including polymorphic dispatch when the item type is discriminated.
Record<unknown>Dictionary-shaped metadata with unknown values.

Generated tests exercise scalar arrays, nested object arrays, dictionaries, and polymorphic collections from fixture samples.

export class FixtureRoot {
tags: string[] = [];
metadata?: Record<string, unknown> | undefined;
contentItems: FixtureContent[] = [];
static loadContentItems(data: Record<string, unknown>[] | unknown[], context?: LoadContext): FixtureContent[] {
return data.map(item => FixtureContent.load(item as Record<string, unknown>, context));
}
static saveContentItems(items: FixtureContent[], context?: SaveContext): Record<string, unknown>[] {
return items.map(item => item.save(context));
}
}

Collections are often where target-specific ergonomics differ. Review the generated target page for the runtime you intend to publish, especially around nullability, unknown values, and dictionary value types.