elysiajs / eden

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

Type error on sample code #45

Open technodromeltd opened 6 months ago

technodromeltd commented 6 months ago

Following EdenTreaty sample from docs:

// server.ts
import { Elysia, t } from 'elysia'

const app = new Elysia()
    .get('/', () => 'Hi Elysia')
    .get('/id/:id', ({ params: { id } }) => id)
    .post('/mirror', ({ body }) => body, {
        body: t.Object({
            id: t.Number(),
            name: t.String()
        })
    })
    .listen(8080)

export type App = typeof app 
import { edenTreaty } from '@elysiajs/eden'
import type { App } from './server' 

const app = edenTreaty<App>('http://localhost:8080')

I get type error:

Type 'Elysia<"", { request: {}; store: {}; derive: {}; resolve: {}; }, { type: {}; error: {}; }, {}, {}, { "/": { get: { body: unknown; params: never; query: unknown; headers: unknown; response: { 200: string; }; }; }; "/id/:id": { get: { body: unknown; params: Record<"id", string>; query: unknown; headers: unknown; respo...' does not satisfy the constraint 'Elysia<any, any, any, any, any, any, false>'. Types have separate declarations of a private property 'dependencies'.ts(2344)

I have

Any idea what else I can test?

biohackerellie commented 5 months ago

+1 for this issue both of these have the same type error as @technodromeltd

export const fetch = edenFetch<App>(
  `${env.API_URL}:${env.API_PORT}`
);

export const app = edenTreaty<App>(
  `${env.API_URL}:${env.API_PORT}`
);
patoliadixit commented 5 months ago

Facing same issue on "eden 0.8.1", and "elysia 0.8.16".

ghost commented 5 months ago

same

heyfixit commented 5 months ago

Same here, went this route: https://elysiajs.com/patterns/unit-test.html#unit-test

used the friendly robots to confer "automated" rather than fancy eden type safety.

chneau commented 3 weeks ago

Here is an example:

https://github.com/chneau/example-elysia-vite/blob/5491c93bdc91d8b566e89f34c37f9ab377b71945/client/src/client.ts#L10

You can run the project with bun install && bun start.

Ther error being: Types have separate declarations of a private property 'dependencies'.

plastic041 commented 3 weeks ago

Here is an example:

https://github.com/chneau/example-elysia-vite/blob/5491c93bdc91d8b566e89f34c37f9ab377b71945/client/src/client.ts#L10

You can run the project with bun install && bun start.

Ther error being: Types have separate declarations of a private property 'dependencies'.

Screenshot 2024-06-28 at 09 57 41

I checked your repo. I think bun has some problems with caching.

  1. Remove both bun.lockbs in client and server directory
  2. Run bun i

Now it doesn't give error. (Tested on 5491c93bdc91d8b566e89f34c37f9ab377b71945)

chneau commented 3 weeks ago

@plastic041 thanks that worked perfectly! @technodromeltd I wonder if you try this too it will fix the issue for you?