elysiajs / eden

Fully type-safe Elysia client
MIT License
169 stars 40 forks source link

Eden Treaty 2 is unable to infer some routes under certain conditions #55

Open MatthewAry opened 8 months ago

MatthewAry commented 8 months ago

Please see https://github.com/MatthewAry/elysia-reproductions/tree/treaty2-cant-resolve-some-routes

If you do something like this:

const nested = new Elysia({ prefix: '/level1/level2' })
  .get('', () => 'Level 2')
  .get("/:id", ({ params: { id }}) => `You are in the identified route! ${id}`);

Eden treaty 2 will not be able to resolve using TS the second route.

MatthewAry commented 8 months ago

The solution is to put a / in the first route I think. If having the path string empty is bad, then maybe TS should throw an error for using an empty string. Nope that didn't work.

MatthewAry commented 8 months ago

It seems that this issue is caused because there is a conflict with how routes are getting resolved. /:id will accept any string between slashes, but the first route is an empty string. Normally you would expect that routes declared before something like a parameterized path would be checked before matching parameterized routes. Elysia probably does this, but Eden Treaty 2's TS path resolver doesn't seem to be handling this condition very well. There's probably more to this, but this is what I'm seeing so far.

SaltyAom commented 7 months ago

Should be fixed in Elysia 1.0.0-rc.11, and Eden 1.0.0-rc.3.