elysiajs / eden

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

Type 'Elysia<...>' does not satisfy the constraint 'Elysia' #77

Open QAdamek opened 5 months ago

QAdamek commented 5 months ago

Am I doing something wrong?

// Server

=================================================
package.json deps:

    "@elysiajs/cookie": "^0.8.0",
    "@elysiajs/cors": "^1.0.2",
    "@elysiajs/jwt": "^0.8.0",
    "@elysiajs/swagger": "^0.8.5",
    "@prisma/client": "5.10.2",
    "elysia": "latest"
=================================================

const app = new Elysia();

app
  .use(swagger())  // It does not change after commenting out this line
  .use(cookie())  // It does not change after commenting out this line
  .use(corsHandler)  // It does not change after commenting out this line
  .use(errorHandler)  // It does not change after commenting out this line
  .use(eventHandler)  // It does not change after commenting out this line
  .use(jwtHandler)  // It does not change after commenting out this line
  .use(authRoutes)
  .listen(process.env.PORT || 4000);

export type App = typeof app;

// type App = Elysia<"", {
//    request: {};
//    store: {};
//    derive: {};
//    resolve: {};
// }, {
//    type: {};
//    error: {};
// }, {}, {}, {}, false> <== This is what VSC is showing when I hover App object
// Client

=================================================
package.json deps:

    "@elysiajs/eden": "latest",
    "elysia": "latest",  // It does not change after commenting out this line
=================================================

import { edenTreaty } from "@elysiajs/eden";
import type { App } from "../../../../project-api/src/index";

const app = edenTreaty<App>("http://localhost:4000");
// Outcome

Type 'Elysia<"", { request: {}; store: {}; derive: {}; resolve: {}; }, { type: {}; error: {}; }, {}, {}, {}, false>' does not satisfy the constraint 'Elysia<any, any, any, any, any, any, any, any>'.
  Type 'Elysia<"", { request: {}; store: {}; derive: {}; resolve: {}; }, { type: {}; error: {}; }, {}, {}, {}, false>' is missing the following properties from type 'Elysia<any, any, any, any, any, any, any, any>': _routes, _types, _ephemeral, _volatile, and 11 more.ts(2344)

Screenshot from 2024-04-05 21-04-48

kelvinwop commented 3 weeks ago

also getting this

kelvinwop commented 3 weeks ago

it seems to work well if

import { treaty } from '@elysiajs/eden';
const app = treaty<App>("localhost:4000")

goes into the same file as the server definition, so maybe a monorepo could fix this