ts-rs icon indicating copy to clipboard operation
ts-rs copied to clipboard

Support `#[ts(as = "...")]` and `#[ts(type = "...")]` on enum variants

Open escritorio-gustavo opened this issue 1 year ago • 3 comments

Goal

Add support for using #[ts(as = "...")] and #[ts(type = "...")] on enum variants to make support for #[serde(with = "...")] (#280) possible here too

Changes

#[ts(as = "...")] and #[ts(type = "...")] are now parsed and processed in enum variants.

Using them currently respects the tag enum representation. That is, neither #[ts(as = "...")] nor #[ts(type = "...")] will eliminate the "tag" or "content" properties the variant would have without them, as that can be achieved by using #[ts(untagged)] on the variant. I don't yet know if this is how serde works, so this can be changed to maintain serde compatibility

Checklist

  • [x] I have followed the steps listed in the Contributing guide.
  • [ ] If necessary, I have added documentation related to the changes made.
  • [ ] I have added or updated the tests related to the changes made.

escritorio-gustavo avatar Mar 22 '24 15:03 escritorio-gustavo

I may need some help on the tests for this. I can't even get #[serde(with = "...")] on variants to compile atm

escritorio-gustavo avatar Mar 22 '24 17:03 escritorio-gustavo

would love to take a loot at this once i find some time 👍

NyxCode avatar Mar 23 '24 13:03 NyxCode

@NyxCode, I think I figured out how #{serde(with = ...)] is used in variants. Looking at the last commit, do you think the current behavior of #[ts(as = ...)] is correct? I think it is, but I still don't quite understand #{serde(with = ...)] deeply enough to be sure

escritorio-gustavo avatar Apr 19 '24 14:04 escritorio-gustavo

I tested my usecase from #352 and can confirm that this works as expected

JonasFocke01 avatar Sep 12 '24 13:09 JonasFocke01

Hi @JonasFocke01, I've just fixed a merge conflict and caused a couple of compiler errors in the process, can you check if it still works?

gustavo-shigueo avatar Sep 12 '24 13:09 gustavo-shigueo

@gustavo-shigueo Workds still as expected :+1:

JonasFocke01 avatar Sep 13 '24 09:09 JonasFocke01