Expand description
TypeScript language exporter.
§Usage
Add specta and specta-typescript to your project:
cargo add specta@2.0.0-rc.23 --features derive,export
cargo add specta-typescript@0.0.10
cargo add specta-serde@0.0.10Next copy the following into your main.rs file:
use specta::{Type, TypeCollection};
use specta_typescript::Typescript;
#[derive(Type)]
pub struct MyType {
pub field: MyOtherType,
}
#[derive(Type)]
pub struct MyOtherType {
pub other_field: String,
}
let mut types = TypeCollection::default()
// We don't need to specify `MyOtherType` because it's referenced by `MyType`
.register::<MyType>();
Typescript::default()
.export_to("./bindings.ts", &types)
.unwrap();Now your setup with Specta!
If you get tired of listing all your types manually? Checkout specta::collect!
Modules§
- primitives
- Primitives provide building blocks for Specta-based libraries.
Macros§
- branded
- Create a branded tuple struct type that exports to TypeScript with a custom name.
Structs§
- Any
- Cast a Rust type to a Typescript
anytype. - Branded
- Runtime payload for a TypeScript branded type.
- Branded
Type Exporter - Reference to Typescript language exporter for branded type callbacks.
- Error
- The error type for the TypeScript exporter.
- Exporter
- Typescript language exporter.
- Framework
Exporter - Reference to Typescript language exporter for framework
- JSDoc
- JSDoc language exporter.
- Never
- Cast a Rust type to a Typescript
nevertype. - Typescript
- JSDoc language exporter.
- Unknown
- Cast a Rust type to a Typescript
unknowntype.
Enums§
- BigInt
Export Behavior - Allows you to configure how Specta’s Typescript exporter will deal with BigInt types (i64, i128 etc).
- Layout
- Allows configuring the format of the final types file
- Serde
Mode - Specifies whether to apply serde transformations for serialization or deserialization
Functions§
- collect_
references - This function collects all Typescript references which are created within the given closure.
- define
- Define a custom Typescript string which can be used as a
DataType::Reference.