use std::collections::HashMap;
use specta::{ResolvedTypes, Type, Types};
use specta_typescript::Typescript;
#[derive(Type)]
pub struct TypeOne {
pub field1: String,
pub field2: i32,
pub test: TypeTwo,
}
#[derive(Type)]
pub struct TypeTwo {
pub field1: String,
pub field2: i32,
pub field3: GenericType<()>,
pub field4: GenericType<i32>,
}
#[derive(Type)]
#[specta(transparent)]
pub struct TransparentWithSkip(#[specta(skip)] (), String);
#[derive(Type)]
pub struct GenericType<A> {
pub my_field: String,
pub generic: A,
}
#[derive(Type, Hash)]
pub enum MyEnum {
A,
B,
C,
}
#[derive(Type)]
pub struct Something {
a: HashMap<MyEnum, i32>,
}
#[derive(Type)]
#[specta(collect = false)]
struct B {
b: u32,
c: C,
}
#[derive(Type)]
#[specta(collect = false)]
struct C {
b: u32,
}
#[derive(Type)]
#[specta(collect = false)]
struct A {
a: B,
c: C,
#[specta(inline)]
d: C,
}
pub struct Selection {
pub name: String,
pub age: i32,
pub password: String,
}
pub type Alias<T> = Option<T>;
pub struct Lol<A> {
pub a: Alias<A>, }
fn main() {
let types = Types::default()
.register::<TypeOne>()
.register::<TransparentWithSkip>()
.register::<GenericType<String>>()
.register::<MyEnum>()
.register::<Something>()
.register::<A>();
Typescript::default()
.export_to("./bindings.ts", &ResolvedTypes::from_resolved_types(types))
.unwrap();
let result = std::fs::read_to_string("./bindings.ts").unwrap();
println!("{result}");
}