Expand description
TypeScript language exporter.
§Usage
Add specta, specta-serde, and specta-typescript to your project:
cargo add specta@2.0.0-rc.25 --features derive,collect
cargo add specta-serde@0.0.12
cargo add specta-typescript@0.0.12Next copy the following into your main.rs file:
use specta::{Type, Types};
use specta_typescript::Typescript;
#[derive(Type)]
pub struct MyType {
pub field: MyOtherType,
}
#[derive(Type)]
pub struct MyOtherType {
pub other_field: String,
}
let mut types = Types::default()
// We don't need to specify `MyOtherType` because it's referenced by `MyType`
.register::<MyType>();
Typescript::default()
.export_to(
"./bindings.ts",
&types,
specta_serde::Format,
)
.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.
- semantic
- Runtime-aware TypeScript type remapping.
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. - BigInt
- Cast a Rust type to a Typescript
biginttype. - 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. - Number
- Cast a Rust type to a Typescript
numbertype. - Typescript
- JSDoc language exporter.
- Unknown
- Cast a Rust type to a Typescript
unknowntype.
Enums§
- Error
Trace Frame - Additional TypeScript exporter context for an
Error. - Layout
- Allows configuring the format of the final types file
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.