Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] Tuples #43

Open
Starwort opened this issue Sep 3, 2023 · 3 comments
Open

[feature request] Tuples #43

Starwort opened this issue Sep 3, 2023 · 3 comments

Comments

@Starwort
Copy link

Starwort commented Sep 3, 2023

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
Copy link
Author

Starwort commented Sep 3, 2023

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

@Wulf
Copy link
Owner

Wulf commented Sep 3, 2023

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
Copy link
Owner

Wulf commented Oct 29, 2023

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]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants