Aleph-Alpha / ts-rs

Generate TypeScript bindings from Rust types
MIT License
989 stars 99 forks source link

bug: Tuples cause imports to be missed #317

Closed HalfVoxel closed 1 month ago

HalfVoxel commented 1 month ago

Describe the bug

When exporting a struct with the following field:

pub variants: Vec<(VariantId, VariantOverview)>,

It is exported as:

// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.

export type DatasetSplit = { field: string | null, variants: Array<[VariantId, VariantOverview]>, };

But there are no imports for the VariantId and VariantOverview types. Imports for other things work correctly.

Expected behavior The generated typescript file has the required imports.

Version

ts-rs = { version = "8.1", features = ["uuid-impl", "chrono-impl"] }

This started appearing when upgrading to version 8.

NyxCode commented 1 month ago

Thanks for opening the issue!
I think I found & fixed that bug in https://github.com/Aleph-Alpha/ts-rs/pull/306#discussion_r1561517414.
I'll try to get the PR merged as soon as I find some time. In the meantime, could you try that branch, and see if it fixes your issue?

ts-rs = { git = "https://github.com/Aleph-Alpha/ts-rs", branch="better-dependencies", features = ["uuid-impl", "chrono-impl"]}

Thanks!

HalfVoxel commented 1 month ago

Thanks! I have already done a workaround in my project, but it definitely looks like that commit will fix the issue. Though, of course, I'd recommend adding a unit test to make sure it never happens again :)

Feel free to close when that PR is merged.

NyxCode commented 1 month ago

fixed in #306

HalfVoxel commented 1 month ago

Thanks. Minor note. The test you added seems to only ensure it can be exported without any errors, but it doesn't actually validate that the output has the imports that this issue mentioned was missing.

NyxCode commented 1 month ago

It does - our CI runs tsc over all outputs.