Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type error with global app.derive followed by onError #722

Closed
bogeychan opened this issue Jul 16, 2024 · 4 comments
Closed

Type error with global app.derive followed by onError #722

bogeychan opened this issue Jul 16, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@bogeychan
Copy link
Contributor

bogeychan commented Jul 16, 2024

What version of Elysia.JS is running?

1.1.0

What platform is your computer?

WSL Ubuntu

What steps can reproduce the bug?

import { Elysia } from "elysia";

new Elysia()
  .derive({ as: "global" }, () => ({
    logger: {
      log(msg: string) {},
    },
  }))
  .onError((ctx) => {
    ctx.logger?.log("yay");
//        ^ Property 'logger' does not exist on type ...
  });

What is the expected behavior?

no type error

What do you see instead?

type error (see comment)

Additional information

Everything besides global works fine.

reported on discord

@bogeychan bogeychan added the bug Something isn't working label Jul 16, 2024
@SaltyAom
Copy link
Member

Should have been fixed with 69eb72a, published under 1.1.2

@bogeychan
Copy link
Contributor Author

@SaltyAom, yes, it fixed it but there's a follow up error:

import { Elysia } from "elysia";

export const logger = new Elysia({ name: "logger" }).derive(
  { as: "global" },
  () => ({
    logger: {
      log(msg: string) {
        console.log(msg);
      },
    },
  })
);

export const error = new Elysia({ name: "error" })
  .use(logger)
  .error({
    Error,
  })
  .onError({ as: "global" }, (ctx) => {
    ctx.logger.log(ctx.code);
//        ^ Property 'logger' does not exist on type ...
  });

new Elysia()
  .use(error)
  .get("/", () => {
    throw new Error("whelp");
  })
  .listen(8080);

The logger exists at runtime but type error as shown in comment.

Open http://localhost:8080/ in browser

@SaltyAom
Copy link
Member

Should have been fixed with 20431a2, published under 1.1.3

@bogeychan
Copy link
Contributor Author

Thanks, works for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants