Skip to content

Commit d99644f

Browse files
committed
Merge branch 'main' of https://github.com/elysiajs/elysia
2 parents da0fa83 + e7218e0 commit d99644f

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

src/index.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2504,7 +2504,7 @@ export default class Elysia<
25042504
*/
25052505
use(
25062506
plugin:
2507-
| Elysia<any, any, any, any, any, any, any, any>
2507+
| MaybePromise<Elysia<any, any, any, any, any, any, any, any>>
25082508
| Elysia<any, any, any, any, any, any, any, any>[]
25092509
| MaybePromise<
25102510
(
@@ -2542,25 +2542,31 @@ export default class Elysia<
25422542
plugin
25432543
.then((plugin) => {
25442544
if (typeof plugin === 'function') {
2545-
return plugin(
2546-
this as unknown as any
2547-
) as unknown as Elysia
2545+
return plugin(this)
2546+
}
2547+
2548+
if (plugin instanceof Elysia) {
2549+
return this._use(plugin)
2550+
}
2551+
2552+
if (typeof plugin.default === 'function') {
2553+
return plugin.default(this)
25482554
}
25492555

2550-
if (typeof plugin.default === 'function')
2551-
return plugin.default(
2552-
this as unknown as any
2553-
) as unknown as Elysia
2556+
if (plugin.default instanceof Elysia) {
2557+
return this._use(plugin.default)
2558+
}
25542559

2555-
return this._use(plugin as any)
2560+
throw new Error(
2561+
'Invalid plugin type. Expected Elysia instance, function, or module with "default" as Elysia instance or function that returns Elysia instance.'
2562+
)
25562563
})
25572564
.then((x) => x.compile())
25582565
)
2566+
return this
2567+
}
25592568

2560-
return this as unknown as any
2561-
} else return this._use(plugin)
2562-
2563-
return this
2569+
return this._use(plugin)
25642570
}
25652571

25662572
private _use(
@@ -5009,6 +5015,7 @@ export type {
50095015
LifeCycleEvent,
50105016
TraceEvent,
50115017
LifeCycleStore,
5018+
LifeCycleType,
50125019
MaybePromise,
50135020
ListenCallback,
50145021
UnwrapSchema,

0 commit comments

Comments
 (0)