Aleph-Alpha/ts-rs

Bug: `#[ts(skip)]` does not work properly in newtype variants of adjacently or internally tagged enums

timephy opened this issue · 2 comments

Explanation

As the title says, the (new) implementation for TypeList uses the type of skipped fields for type dependencies.
This requires those types to implement TS, which some do not (like anyhow::Error, see image below).

This happens to me when using the feature implemented in #180.

Errors:

  • "the trait bound anyhow::Error: TS is not satisfied"
  • "the method extend exists for associated type impl TypeList, but its trait bounds were not satisfied"
image

Expectation

TypeList skips the type of skipped fields.

Context

I'd like to update the version used in one of my projects to the current version of the main branch with the new doc support on types, but this breaks dozens of my error-types (as seen in the image above).

Are you sure that you're compiling with the serde-compat feature enabled? If not, then the #[serde(...)] attributes have no effect.

Ah, okay, seems like you found a regression!
I suspect it wasn't introduced with TypeList, but together with the rework of enums.

This here works

struct Unsupported;

#[derive(TS, Serialize)]
enum X {
    A (
        #[serde(skip)]
        Unsupported
    ),
}

But adding #[serde(tag = "t")] doesn't:

struct Unsupported;

#[derive(TS, Serialize)]
#[serde(tag = "t")]
enum X {
    A (
        #[serde(skip)]
        Unsupported
    ),
}
error[E0277]: the trait bound `Unsupported: TS` is not satisfied  

This also seems to only happen with tuple newtype variants. A { #[serde(skip)] x: Unsupported } and A (#[serde(skip)] Unsupported, i32) works.