@@ -2504,7 +2504,7 @@ export default class Elysia<
2504
2504
*/
2505
2505
use (
2506
2506
plugin :
2507
- | Elysia < any , any , any , any , any , any , any , any >
2507
+ | MaybePromise < Elysia < any , any , any , any , any , any , any , any > >
2508
2508
| Elysia < any , any , any , any , any , any , any , any > [ ]
2509
2509
| MaybePromise <
2510
2510
(
@@ -2542,25 +2542,31 @@ export default class Elysia<
2542
2542
plugin
2543
2543
. then ( ( plugin ) => {
2544
2544
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 )
2548
2554
}
2549
2555
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
+ }
2554
2559
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
+ )
2556
2563
} )
2557
2564
. then ( ( x ) => x . compile ( ) )
2558
2565
)
2566
+ return this
2567
+ }
2559
2568
2560
- return this as unknown as any
2561
- } else return this . _use ( plugin )
2562
-
2563
- return this
2569
+ return this . _use ( plugin )
2564
2570
}
2565
2571
2566
2572
private _use (
@@ -5009,6 +5015,7 @@ export type {
5009
5015
LifeCycleEvent ,
5010
5016
TraceEvent ,
5011
5017
LifeCycleStore ,
5018
+ LifeCycleType ,
5012
5019
MaybePromise ,
5013
5020
ListenCallback ,
5014
5021
UnwrapSchema ,
0 commit comments