Skip to main content

Crate specta_typescript

Crate specta_typescript 

Source
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.10

Next 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 any type.
Branded
Runtime payload for a TypeScript branded type.
BrandedTypeExporter
Reference to Typescript language exporter for branded type callbacks.
Error
The error type for the TypeScript exporter.
Exporter
Typescript language exporter.
FrameworkExporter
Reference to Typescript language exporter for framework
JSDoc
JSDoc language exporter.
Never
Cast a Rust type to a Typescript never type.
Typescript
JSDoc language exporter.
Unknown
Cast a Rust type to a Typescript unknown type.

Enums§

BigIntExportBehavior
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
SerdeMode
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.