| Crates.io | ts-type |
| lib.rs | ts-type |
| version | 1.0.2 |
| created_at | 2025-04-17 05:52:44.357079+00 |
| updated_at | 2026-01-08 19:23:45.30327+00 |
| description | Utilities and types for working with TypeScript type representations in Rust. |
| homepage | |
| repository | https://github.com/ryangoree/wasm-utils-rs |
| max_upload_size | |
| id | 1637264 |
| size | 56,548 |
ts-type helps Rust code reason about TypeScript types. It provides a
structured representation of TypeScript syntax together with helper macros and
conversions that are friendly to procedural macros such as
ts-macro.
TsType enum models common TypeScript constructs (unions, tuples, generics,
indexed access, arrays) with predictable Display output.ts_type! macro builds TsType values using TypeScript syntax and allows
interpolation of previously built fragments.ToTsType trait turn &str or syn::Type values into TsType,
with special behaviour for Option<T> and Vec<T> to map to
T | undefined and T[] respectively.TsTypeError and type_error_at! macro surface precise parsing
locations when something cannot be represented.use ts_type::{ts_type, TsType};
let binding: TsType = ts_type!(Record<string, (number | boolean)[]>);
assert_eq!(binding.to_string(), "Record<string, (number | boolean)[]>");
syn::Typeuse syn::parse_quote;
use ts_type::ToTsType;
let rust_ty: syn::Type = parse_quote!(Option<Vec<String>>);
let ts_ty = rust_ty.to_ts_type().unwrap();
assert_eq!(ts_ty.to_string(), "string[] | undefined");
ts-macrots-type powers the #[ts] attribute. The macro uses
ToTsType to infer field types and compose the final TypeScript interface that
gets emitted alongside your bindings.
Licensed under the Apache-2.0 license.