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

Typesafe isn't functioning properly on Eden Treaty 2 #58

Open
hagishi opened this issue Mar 13, 2024 · 1 comment
Open

Typesafe isn't functioning properly on Eden Treaty 2 #58

hagishi opened this issue Mar 13, 2024 · 1 comment

Comments

@hagishi
Copy link

hagishi commented Mar 13, 2024

Hi
After testing various things with the RC version, it didn't work correctly. Below is the code I ran

describe("eden test", () => {
  it("derive test", async () => {
    const app = new Elysia()
      .derive(() => ({ user: "name" }))
      .get("/user", () => "user")
    treaty(app).get("/user", () => "user")
  })

  it("resolve test", async () => {
    const app = new Elysia()
      .resolve(() => ({ user: "name" }))
      .get("/user", () => "user")
    treaty(app).user.get("/user", () => "user")
  })

  it("prefix test", async () => {
    const app = new Elysia({ prefix: undefined }).get("/user", () => "user")
    treaty(app).user.user.get() //<-- this is wrong (This is how it's autocompleted.)
  })
})

capture
image

version
elysia: 1.0.0-rc.15
@elysiajs/eden: 1.0.0-rc.4

@hagishi
Copy link
Author

hagishi commented Mar 13, 2024

When we use { as: 'global' }, it will work properly.

describe("eden test", () => {
  it("derive local test", async () => {
    const app = new Elysia()
      .derive(() => ({ user: "name" }))
      .get("/user", ({ user }) => user);
    treaty(app).user.get(); // <- type error
  });

  it("derive global test", async () => {
    const app = new Elysia()
      .derive({ as: "global" }, () => ({ user: "name" }))
      .get("/user", ({ user }) => user);
    treaty(app).user.get(); // <- ok
  });
});
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant