Skip to content

~Routes exposes decoded (output) types instead of input types, breaking Eden type inference for transformed schemas #1824

@Horuse

Description

@Horuse

What version of Elysia is running?

1.4.28

What platform is your computer?

Darwin 23.6.0 arm64 arm

What environment are you using

bun 1.3.8

Are you using dynamic mode?

no

What steps can reproduce the bug?

import { Elysia, t, type UnwrapBodySchema } from "elysia";
import { treaty } from "@elysiajs/eden";

// TypeBox Mocked Transform
const Base64 = t
  .Transform(t.String({ description: "Base64-encoded Uint8Array" }))
  .Decode((base64: string): Uint8Array => new Uint8Array())
  .Encode((bytes: Uint8Array): string => "");

const app = new Elysia()
  .post("/register", ({ body: { key } }) => ({ success: true }), // (parameter) key: Uint8Array
    {
      body: t.Object({
        key: Base64, // (property) key: TTransform<TString, Uint8Array>
      }),
    }
  )
  .listen(3000);

// ~Routes always stores decoded/output types — input types are lost

type RegisterBody = (typeof app)["~Routes"]["register"]["post"]["body"];
// type RegisterBody = { key: Uint8Array }  <- should be { key: string }

type TypeBoxResult = UnwrapBodySchema<typeof Base64>;
// type TypeBoxResult = Uint8Array <- should be string

// ---

const api = treaty(app);

// Type 'string' is not assignable to type 'Uint8Array'
await api.register.post({ key: "someBase64String" });

What is the expected behavior?

~Routes should expose both input (wire) and output (decoded) types for each route, so consumers like @elysiajs/eden can infer the correct client-side types. For a route with t.Transform(t.String()).Decode(...), the body input type should be string.

What do you see instead?

~Routes only stores decoded/output types. For a route with t.Transform(t.String()).Decode((v): Uint8Array => ...), the body type is inferred as Uint8Array instead of string, forcing @elysiajs/eden to require the decoded type on the client side.

Additional information

@elysiajs/eden: 1.4.8

Have you try removing the node_modules and bun.lockb and try again yet?

yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions