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 inference not working for derive/resolve coming from plugin #580

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

Comments

@JohnRoseDev
Copy link

JohnRoseDev commented Mar 30, 2024

What version of Elysia.JS is running?

1.0.9

What platform is your computer?

Darwin 22.5.0 x86_64 i386

What steps can reproduce the bug?

The docs introduce a service locator pattern in order to correctly use decorated values in other instances (https://elysiajs.com/essential/plugin.html#service-locator).

This works:

import { Elysia } from 'elysia'

const setup = new Elysia({ name: 'setup' }
  .decorate(() => {
    return { user: 'user' };
  })

const main = new Elysia()
  .use(setup)
  .get('/', ({ user }) => user);

But using derive or resolve instead of decorate will not work:

import { Elysia } from 'elysia'

const setup = new Elysia({ name: 'setup' })
  .resolve(() => { // same happens with derive
    return { user: 'user' };
  })

const main = new Elysia()
  .use(setup)
  .get('/', ({ user }) => user); // TS2339: Property  user  does not exist on type ...

Is it not possible to encapsulate resolve/derive logic into plugins while maintaining type inference? Is this a bug or limitation of Elysia?

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response

@JohnRoseDev JohnRoseDev added the bug Something isn't working label Mar 30, 2024
@cybercoder-naj
Copy link

Refer #513

@JohnRoseDev
Copy link
Author

Refer #513

Thanks. Setting the hooks as global fixes the TS issues.

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