pub trait TypeScript {
// Required method
fn typescript() -> TypeDef;
}Expand description
The core trait for types that can be represented as TypeScript.
This is the foundation trait for ferrotype, similar to how Serialize is
the foundation of serde. Implementations return a TypeDef that describes
the TypeScript representation of the type.
§Design Philosophy
Unlike string-based approaches, returning a structured TypeDef enables:
- Deduplication: Named types can be collected and emitted once
- Analysis: Dependencies between types can be tracked
- Flexibility: The IR can be rendered in different styles
- Composition: Complex types build from simpler TypeDefs
§Example
ⓘ
use ferrotype::{TypeScript, TypeDef, Primitive};
struct UserId(String);
impl TypeScript for UserId {
fn typescript() -> TypeDef {
TypeDef::Named {
name: "UserId".into(),
def: Box::new(TypeDef::Primitive(Primitive::String)),
}
}
}Required Methods§
Sourcefn typescript() -> TypeDef
fn typescript() -> TypeDef
Returns the TypeScript type definition for this type.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.