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

fix: support for module promise in Elysia#use #546

Merged
merged 2 commits into from
Mar 18, 2024

Conversation

aleclarson
Copy link
Contributor

The following use case was broken: Calling app.use(import("./routes")) where the "./routes" module has a default export that is an Elysia instance.

I‘m doing instanceof Elysia checks on the promise result and the module‘s "default" export, so a more informative error can be thrown, where before the app would crash with some obscure TypeError with a message of "Right side of assignment cannot be destructured" within the Elysia#_use method.

The following use case was broken: Calling `app.use(import("./routes"))` where the "./routes" module has a default export that is an Elysia instance.

I‘m doing `instanceof Elysia` checks on the promise result and the module‘s "default" export, so a more informative error can be thrown, where before the app would crash with some obscure TypeError with a message of "Right side of assignment cannot be destructured" within the `Elysia#_use` method.

return this._use(plugin as any)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue was that plugin.default was not being referenced here, i.e. plugin.default || plugin. But also, I decided to clean up this area of the code, removing unnecessary type casts and adding instanceof checks for proper type narrowing.

@SaltyAom SaltyAom merged commit 92f9afb into elysiajs:main Mar 18, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants