pub enum TypeDef {
Primitive(Primitive),
Array(Box<TypeDef>),
Tuple(Vec<TypeDef>),
Object(Vec<Field>),
Union(Vec<TypeDef>),
Intersection(Vec<TypeDef>),
Record {
key: Box<TypeDef>,
value: Box<TypeDef>,
},
Named {
name: String,
def: Box<TypeDef>,
},
Ref(String),
Literal(Literal),
Function {
params: Vec<Field>,
return_type: Box<TypeDef>,
},
Generic {
base: String,
args: Vec<TypeDef>,
},
}Expand description
Intermediate representation for TypeScript types.
This enum represents all TypeScript types that ferrotype can generate. It serves as the IR between Rust types and TypeScript output, enabling analysis and transformation before rendering.
§Type Categories
- Primitives:
string,number,boolean,null, etc. - Compounds: Arrays, tuples, objects, unions, intersections
- References: Named types and type references
- Literals: Specific string, number, or boolean values
Variants§
Primitive(Primitive)
A primitive TypeScript type.
Array(Box<TypeDef>)
An array type: T[]
Tuple(Vec<TypeDef>)
A tuple type: [T1, T2, ...]
Object(Vec<Field>)
An object type with named fields: { field1: T1; field2?: T2; }
Union(Vec<TypeDef>)
A union type: T1 | T2 | ...
Intersection(Vec<TypeDef>)
An intersection type: T1 & T2 & ...
Record
A record/dictionary type: Record<K, V> or { [key: K]: V }
Named
A named type definition that should be emitted as a separate declaration. This is the primary mechanism for type deduplication.
Ref(String)
A reference to a named type. Used to avoid infinite recursion and to generate cleaner output by referencing previously-defined types.
Literal(Literal)
A literal type with a specific value.
Function
A function type: (arg1: T1, arg2: T2) => R
Generic
A generic type application: Generic<T1, T2>