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

[WIP] `skip_serializing_if` assumes that object’s field may not exist

Open manifest opened this issue 8 months ago • 5 comments

Goal

Closes #394

Changes

I've added parsing and handing of serde’s helper-attribute parameter skip_serializing_if.

Checklist

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

manifest avatar Mar 28 '25 07:03 manifest

This is intentionally not supported, see #204

gustavo-shigueo avatar Mar 28 '25 11:03 gustavo-shigueo

I have re-opened this for now to let us experiment with the special-cases I outlined in #394 a bit. The two special-cases I'd like to play with first are

#[serde(skip_serializing_if = "<anything>", default)]
x: T // => x?: T

and

#[serde(skip_serializing, default)]
x: T // => x?: T

NyxCode avatar Apr 05 '25 11:04 NyxCode

Hey @NyxCode, I see you marked the PR as [WIP] is there anything else you want to add before merging? If that's because of my commits, I was just resolving the merge conflict

gustavo-shigueo avatar Apr 05 '25 18:04 gustavo-shigueo

@gustavo-shigueo Yeah, I think there are some open questions here still - and I couldn't find the "convert to draft" button ^^

NyxCode avatar Apr 05 '25 18:04 NyxCode

Yeah, I think there are some open questions here still - and I couldn't find the "convert to draft" button ^^

Oh okay, lol

gustavo-shigueo avatar Apr 05 '25 18:04 gustavo-shigueo

We could possibly emit an error/warning to prevent users from running into TS1257: A required element cannot follow an optional element. for tuple structs.

NyxCode avatar Jun 03 '25 13:06 NyxCode

I have updated the description - I'd appreciate if you could take a look at this when you find some time @gustavo-shigueo. No hurry, tho.

NyxCode avatar Jun 03 '25 14:06 NyxCode