Skip to main content

specta_typescript/
lib.rs

1//! [TypeScript](https://www.typescriptlang.org) language exporter.
2//!
3//! # Usage
4//!
5//! Add `specta` and `specta-typescript` to your project:
6//!
7//! ```bash
8//! cargo add specta@2.0.0-rc.23 --features derive,export
9//! cargo add specta-typescript@0.0.10
10//! cargo add specta-serde@0.0.10
11//! ```
12//!
13//! Next copy the following into your `main.rs` file:
14//!
15//! ```rust
16//! use specta::{Type, TypeCollection};
17//! use specta_typescript::Typescript;
18//!
19//! #[derive(Type)]
20//! pub struct MyType {
21//!     pub field: MyOtherType,
22//! }
23//!
24//!
25//! #[derive(Type)]
26//! pub struct MyOtherType {
27//!     pub other_field: String,
28//! }
29//!
30//! let mut types = TypeCollection::default()
31//!     // We don't need to specify `MyOtherType` because it's referenced by `MyType`
32//!     .register::<MyType>();
33//!
34//! Typescript::default()
35//!     .export_to("./bindings.ts", &types)
36//!     .unwrap();
37//! ```
38//!
39//! Now your setup with Specta!
40//!
41//! If you get tired of listing all your types manually? Checkout `specta::collect`!
42//!
43#![cfg_attr(docsrs, feature(doc_cfg))]
44#![doc(
45    html_logo_url = "https://github.com/specta-rs/specta/raw/main/.github/logo-128.png",
46    html_favicon_url = "https://github.com/specta-rs/specta/raw/main/.github/logo-128.png"
47)]
48
49mod branded;
50mod error;
51mod exporter;
52mod jsdoc;
53mod legacy; // TODO: Remove this
54mod opaque;
55pub mod primitives;
56mod references;
57pub(crate) mod reserved_names;
58mod types;
59mod typescript;
60
61pub use branded::Branded;
62pub use error::Error;
63pub use exporter::{
64    BigIntExportBehavior, BrandedTypeExporter, Exporter, FrameworkExporter, Layout,
65};
66pub use jsdoc::JSDoc;
67pub use opaque::define;
68pub use references::collect_references;
69pub use types::{Any, Never, Unknown};
70pub use typescript::Typescript;
71
72// Re-export SerdeMode from specta-serde for convenience
73pub use specta_serde::SerdeMode;