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

Versions 1.1.21 through 1.1.26 break end-to-end type safety with eden treaty #934

Open
lunarW1TCH opened this issue Dec 5, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@lunarW1TCH
Copy link

lunarW1TCH commented Dec 5, 2024

What version of Elysia is running?

1.1.20 - 1.1.26

What platform is your computer?

Microsoft Windows NT 10.0.22631.0 x64

What steps can reproduce the bug?

Create an Elysia route with response validation:

new Elysia().post('', async () => { 
// ...
}, {
  response: {
    200: t.UnionEnum(['user has joined already', 'added free plan']),
    401: t.String(),
  },
  body: t.Object({
    agreedOnDataTerms: t.Boolean(),
  }),
})

Then create an eden treaty client for this route.

treaty<Route>(getBaseUrl()).index.post

What is the expected behavior?

image
This is the correct type output for versions 1.1.20 and below.

What do you see instead?

image
This is the type output for versions 1.1.21 through 1.1.26

Only the response is inferred incorrectly.

Additional information

I am using Elysia for Route Handlers in NextJS 15. Eden Treaty version is 1.1.3

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

Yes, multiple times, tried different Elysia versions as well.

@lunarW1TCH lunarW1TCH added the bug Something isn't working label Dec 5, 2024
@jvidalv
Copy link

jvidalv commented Dec 10, 2024

Same experience here, I use it with expo-router on an expo app.

Eden version "@elysiajs/eden": "1.1.3",, anything bigger than "elysia": "1.1.20", breaks types for async handlers.

Reproduction is simple, just slam an async on any route, types stop working, here is an example:

import { Elysia, t } from "elysia";

export const pokemons = new Elysia({ prefix: "/pokemons" }).get(
  "/",
  async () => {
    const pokemons = await fetch(
      "https://pokeapi.co/api/v2/pokemon/?limit=20&offset=20",
    );

    const response = (await pokemons.json()) as {
      results: { name: string; url: string }[];
    };

    return { success: true, message: response.results };
  },
  {
    response: t.Object({
      success: t.Boolean(),
      message: t.Array(
        t.Object({
          name: t.String(),
          url: t.String(),
        }),
      ),
    }),
  },
);

This works well on elysiajs 1.1.20 and treaty 1.1.3

@chayutzee
Copy link

chayutzee commented Dec 15, 2024

Did you install @types/bun into project that want to use treaty ?
@lunarW1TCH @jvidalv

@lunarW1TCH
Copy link
Author

I did not, I am using bun only as a dependency manager. Adding bun types breaks the app in multiple places.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants