Aleph-Alpha/ts-rs

Make `Option` different in the struct

Closed this issue · 2 comments

Is it possible?

pub struct A {
  b: u8,
  c: Option<u8>
}

expect

export interface A {
  b: number,
  c: number | null | undefined,
  //Or like this if in struct
  c?: number 
}

I think it may be possible, but since serde converts None to null, I don't think it would behave as you expect

This should do what you want

#[derive(ts_rs::TS)]
pub struct A {
  b: u8,
  #[ts(optional)]
  c: Option<u8>
}