Crate tauri_ts_generator

Crate tauri_ts_generator 

Source
Expand description

§tauri-ts-generator

A CLI tool and library for generating TypeScript bindings from Tauri commands.

This crate scans your Rust code for #[tauri::command] macros and automatically generates:

  • TypeScript interfaces for your Rust structs and enums.
  • TypeScript wrapper functions to invoke your commands.

It is designed to ensure type safety between your Rust backend and TypeScript frontend, reducing boilerplate and runtime errors.

§Features

  • Automated Parsing: Uses syn to parse Rust AST.
  • Async Support: Correctly handles async commands.
  • Type Mapping: Converts Rust types to their TypeScript equivalents.
  • Custom Types: Supports struct and enum with serde serialization.

§Usage

Although primarily used as a CLI tool, you can also use it as a library:

use tauri_ts_generator::config::Config;
use tauri_ts_generator::pipeline::Pipeline;

fn main() -> anyhow::Result<()> {
    let config = Config::default_config();
    let pipeline = Pipeline::new(false);
    pipeline.run(&config)?;
    Ok(())
}

Modules§

cargo_expand
Cargo expand support for parsing macro-generated types
cli
config
generator
known_types
Known types module - centralized list of known Rust types and their TypeScript mappings
models
Data models for representing Tauri commands and Rust types.
parser
pipeline
Pipeline module - orchestrates the code generation process
resolver
Module resolver - resolves types based on imports and module structure
scanner
utils

Derive Macros§

TS
Derive macro that enables #[ts(...)] attributes on struct/enum fields.