Skip to content

Conversation

@simoncozens
Copy link
Contributor

Typeshare can't handle Rust types which contain a tuple. This is annoying, because my Rust types do contain a tuple! But it's even more annoying because I'm planning to tell typeshare explicitly what those types should become in the target language using the type= decorator - so it doesn't even matter that my types contain tuples, because they're immediately overridden and Typeshare doesn't even need to care about them.

This PR moves the parse-time failure to emit time, by storing the parse failure inside a RustType::Unrepresentable variant. If this RustType has a type override, then there's no problem; if there are no type overrides, the unrepresentable type can't be emitted, and then there's a problem.

So:

struct Foo {
    #[typeshare(ypescript(type = "Array<[number, number]>"))]
    pub vec_tuple: Option<Vec<(i32, i32)>>
}
$ typeshare src --lang=typescript --output-file=foo.ts

[2025-12-12 15:45:05.594187 +00:00] INFO [cli/src/main.rs:78] typeshare started generating types
[2025-12-12 15:45:05.594317 +00:00] INFO [cli/src/main.rs:85] Using directories: ["src"]
[2025-12-12 15:45:05.621167 +00:00] INFO [cli/src/main.rs:141] typeshare started writing 1 generated types
[2025-12-12 15:45:05.621732 +00:00] INFO [cli/src/main.rs:148] typeshare finished generating types

$ typeshare src --lang=python --output-file=foo.py

[2025-12-12 15:45:23.641500 +00:00] INFO [cli/src/main.rs:78] typeshare started generating types
[2025-12-12 15:45:23.641712 +00:00] INFO [cli/src/main.rs:85] Using directories: ["src"]
[2025-12-12 15:45:23.669306 +00:00] INFO [cli/src/main.rs:141] typeshare started writing 1 generated types
[2025-12-12 15:45:23.670078 +00:00] ERROR [cli/src/main.rs:72] typeshare failed to generate types: Tuples are not allowed in typeshare types at line 13, column 30
Error: Tuples are not allowed in typeshare types at line 13, column 30

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

Successfully merging this pull request may close these issues.

1 participant