elysiajs / eden

Fully type-safe Elysia client
MIT License
147 stars 37 forks source link

Cannot pass wildcard params (+Workaround) #96

Open jakob-kruse opened 3 months ago

jakob-kruse commented 3 months ago

Problem

It currently is not possible to provide wildcard parameters with eden treaty.

With dynamic params the client type is this:

api: {
  files: ((params: {
    path: string | number;
  }) => {
  // ...

With a wildcard it becomes this:

api: {
  files: {
    "*": {
    // ...

It should also become a function in my opinion. Please let me know if i missed something or you need a reproduction repo!

Workaround / Repro:

export const api = new Elysia({ prefix: '/api' })
  // Never called just used for types
  .get('/files/:path', ({ params }) => {
    return doStuff(params.path);
  })
  .get('/files/*', ({ params }) => {
    return doStuff(params['*']);
  });

export type Api = typeof api;

async function clientCode() {
  await apiClient.api.files({ path: '/test/path' }).get();
}