elysiajs / eden

Fully type-safe Elysia client
MIT License
173 stars 41 forks source link

Type error on sample code #45

Open technodromeltd opened 10 months ago

technodromeltd commented 10 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 9 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 9 months ago

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

ghost commented 9 months ago

same

heyfixit commented 9 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 5 months 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 5 months 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 5 months ago

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

chneau commented 4 months ago

@plastic041 Hello, for some reason I have the same issue again, I have to add a // @ts-expect-error again on the treaty<Server> else I have this TS error Types have separate declarations of a private property 'dependencies'..

I'm basically on latest version.

https://github.com/chneau/example-elysia-vite/blob/d2731f42f94a2d7a7d720a3266e5947d963baa35/client/src/client.ts#L9

Same issue as the creator of this issue.

plastic041 commented 4 months ago

@chneau I get the same error and I can't find the right way to handle this either 😢

Bobetti commented 3 months ago

How it is possible that code example is not working! Just copy-pasted from documentation and got the same error! The topic was created 13th of January, now is August 16th - and still no solution. Dead framework, Stay Away!

kinbuild commented 1 month ago

Also broken for me :(