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