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

Missing resolved properties on onBeforeHandle and models of a route. #545

Closed
VaronLaStrauss opened this issue Mar 17, 2024 · 2 comments
Closed
Labels
bug Something isn't working

Comments

@VaronLaStrauss
Copy link

What version of Elysia.JS is running?

1.0.0

What platform is your computer?

Linux 5.15.133.1-microsoft-standard-WSL2 x86_64 x86_64

What steps can reproduce the bug?

import { Elysia, t } from "elysia";

const resolvedUser = new Elysia().resolve(() => {
  return { user: "I am a user" };
});

const model = new Elysia().model("somebody", t.String());

const app = new Elysia()
  .use(resolvedUser)
  .onBeforeHandle(
    { as: "local" },
    (
      // Property 'user' does not exist on type '{ body: unknown; query: Record<string, string | undefined>; ...
      { user },
    ) => {},
  )
  .get("/", () => {}, {
    // Type 'string' is not assignable to type 'TSchema'
    body: "somebody",
  });

What is the expected behavior?

Same as with versions <=0.8, to be able to resolve types on hooks.

What do you see instead?

No intellisense for hooks and models.

Additional information

No response

@SaltyAom
Copy link
Member

See #513

Since your resolve is local, it isn't inherited by the parent instance.

You need to add { as: 'global' } to resolve to fix this.

const resolvedUser = new Elysia().resolve({ as: 'global' }, () => {
  return { user: "I am a user" };
});

@kabir-asani
Copy link

See #513

Since your resolve is local, it isn't inherited by the parent instance.

You need to add { as: 'global' } to resolve to fix this.

const resolvedUser = new Elysia().resolve({ as: 'global' }, () => {
  return { user: "I am a user" };
});

This absolutely works! Thank you so much.

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

3 participants