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.24 --features derive,export
9//! cargo add specta-typescript@0.0.11
10//! cargo add specta-serde@0.0.11
11//! ```
12//!
13//! Next copy the following into your `main.rs` file:
14//!
15//! ```rust
16//! use specta::{ResolvedTypes, 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//! let resolved_types = ResolvedTypes::from_resolved_types(types);
34//!
35//! Typescript::default()
36//!     .export_to("./bindings.ts", &resolved_types)
37//!     .unwrap();
38//! ```
39//!
40//! Now your setup with Specta!
41//!
42//! If you get tired of listing all your types manually? Checkout `specta::collect`!
43//!
44#![cfg_attr(docsrs, feature(doc_cfg))]
45#![doc(
46    html_logo_url = "https://github.com/specta-rs/specta/raw/main/.github/logo-128.png",
47    html_favicon_url = "https://github.com/specta-rs/specta/raw/main/.github/logo-128.png"
48)]
49
50mod branded;
51mod error;
52mod exporter;
53mod jsdoc;
54mod legacy; // TODO: Remove this
55mod map_keys;
56mod opaque;
57pub mod primitives;
58mod references;
59pub(crate) mod reserved_names;
60mod types;
61mod typescript;
62
63pub use branded::Branded;
64pub use error::Error;
65pub use exporter::{BrandedTypeExporter, Exporter, FrameworkExporter, Layout};
66pub use jsdoc::JSDoc;
67pub use opaque::define;
68pub use references::collect_references;
69pub use types::{Any, Never, Unknown};
70pub use typescript::Typescript;