Skip to content

Vec<u8> does not map to Uint8Array when using serde_bytes #440

@hexadecimal233

Description

@hexadecimal233

When using specta to generate TypeScript types for a Rust struct containing a Vec<u8> annotated with serde_with = "serde_bytes", the generated frontend types do not align with the Uint8Array expected by MessagePack. (the protocol im using in creating frontend app)

Currently Specta ignores the serde_bytes logic and attempts to treat Vec<u8> as a standard number[].

There's a workaround to trick the compiler:

#[derive(Type, Serialize, Deserialize)]
pub struct MyPayload {
    #[specta(type = Unknown)] // Workaround to bypass TS errors
    #[serde(with = "serde_bytes")] 
    pub screenshot: Vec<u8>,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    breaking changeThis will probs end up in the next major version.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions