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

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

Merged
merged 8 commits into from
Sep 16, 2024

Conversation

escritorio-gustavo
Copy link
Contributor

@escritorio-gustavo escritorio-gustavo commented Mar 22, 2024

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

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

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

@NyxCode
Copy link
Collaborator

NyxCode commented Mar 23, 2024

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

@escritorio-gustavo escritorio-gustavo added enhancement New feature or request help wanted Extra attention is needed labels Apr 17, 2024
@escritorio-gustavo
Copy link
Contributor Author

@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

@JonasFocke01
Copy link

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

@gustavo-shigueo
Copy link
Collaborator

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?

@JonasFocke01
Copy link

@gustavo-shigueo Workds still as expected 👍

Copy link
Collaborator

@NyxCode NyxCode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nicely done!

@gustavo-shigueo gustavo-shigueo merged commit 9763ca0 into main Sep 16, 2024
18 checks passed
@gustavo-shigueo gustavo-shigueo deleted the type_override_variants branch September 16, 2024 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants