tsync icon indicating copy to clipboard operation
tsync copied to clipboard

[feature request] Tuples

Open Starwort opened this issue 1 year ago • 3 comments

Currently, it seems that tuples (or at least, optional tuples) are output as 'unknown' - TypeScript has a tuple type, so it should be fairly easy to convert between Rust tuples and TypeScript tuples?

#[tsync]
struct HasTuple {
    foo: i32,
    bar: Option<(String, i32)>,
}
// Current output
interface HasTuple {
  foo: number;
  bar?: unknown;
}
// Ideal output
interface HasTuple {
  foo: number;
  bar?: [string, number]; // TypeScript tuple syntax
}

Starwort avatar Sep 03 '23 09:09 Starwort

According to the syn docs, this should be as simple as matching on syn::Type::Tuple(TypeTuple) and then using the inner TypeTuple to get the necessary data

Starwort avatar Sep 03 '23 09:09 Starwort

Thanks again for the write up @Starwort. I agree, this should be very doable! Again, I’d love help implementing this but at the moment I won’t be able to address this right away.

Wulf avatar Sep 03 '23 19:09 Wulf

Alongside supporting tuples themselves, it would be nice to also support structs, as noted in #46:

Input: struct Todo(i32, String)

Output: type Todo = [number, string]

Wulf avatar Oct 29 '23 02:10 Wulf