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

Type wants me to add .index to api function chain before HTTP verb after v1.0 #71

Open
brianjor opened this issue Mar 25, 2024 · 2 comments

Comments

@brianjor
Copy link

brianjor commented Mar 25, 2024

"@elysiajs/eden": "1.0.5",
"elysia": "1.0.7"

index.ts:

import { edenTreaty } from "@elysiajs/eden";
import Elysia from "elysia";

const helloHandlers = new Elysia().get("", () => "hello");

const routes = new Elysia().group("/hello", (_) => _.use(helloHandlers));

const app = new Elysia().use(routes).listen(3000);

const eden = edenTreaty<typeof app>("localhost:3000");

console.log((await eden.hello.get()).data); // <-- has red squiggly, but works!
console.log((await eden.hello.index.get()).data); // <-- no red squiggly, "NOT_FOUND"

app.stop();

output from running:

bun run index.ts
hello
NOT_FOUND

Error message:

Property 'get' does not exist on type '{ index: { get: (params?: { $fetch?: RequestInit | undefined; getRaw?: boolean | undefined; $transform?: Transform<unknown> | undefined; $query?: Record<string, string> | undefined; $headers?: Record<...> | undefined; } | undefined, options?: { ...; } | undefined) => Promise<...>; }; }'
@brianjor brianjor changed the title Have to add .index to api function chain before HTTP verb after 1.0 Type wants me to add .index to api function chain before HTTP verb after v1.0 Mar 25, 2024
@kidqueb
Copy link

kidqueb commented Apr 6, 2024

I can fix this depending on what the actual expectations are.

Leave .index incase someone decides to use an http verb in their route itself, causing a collision on .get() or whatever the verb was, or do we strip index and assume people wont be using http verbs in their routes?

  1. eden.hello.index.get() should return data.
  2. eden.hello.index.get() should show a type error and eden.hello.get() should return data.

@brianjor
Copy link
Author

brianjor commented Apr 7, 2024

I am expecting eden.hello.get() to return data, as it was pre 1.0. It still does, as shown in the example, it's just the warning is blocking CI/CD checks preventing me from updating.

I would prefer not to have to add .index to the api calls.

Also this only seems to be an issue with routes behind group.
See:

import { edenTreaty } from "@elysiajs/eden";
import Elysia from "elysia";

const helloHandlers = new Elysia().get("", () => "hello");

const routes = new Elysia()
  .get("/goodbye", () => "bye")
  .group("/hello", (_) => _.use(helloHandlers));

const app = new Elysia().use(routes).listen(3000);

const eden = edenTreaty<typeof app>("localhost:3000");

console.log((await eden.hello.get()).data); // <-- has red squiggly, but works!
console.log((await eden.hello.index.get()).data); // <-- no red squiggly, "NOT_FOUND"

console.log((await eden.goodbye.get()).data); // <-- no squiggly, working as expected

app.stop();

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

2 participants