11import assert from 'assert' ;
2- import KoaRouter from 'koa-router' ;
3- import { Context } from 'egg' ;
2+ import { Context , Router } from 'egg' ;
43import {
54 EggContext ,
65 HTTPControllerMeta ,
@@ -25,8 +24,8 @@ const noop = () => {
2524} ;
2625
2726export class HTTPMethodRegister {
28- private readonly router : KoaRouter < any , Context > ;
29- private readonly checkRouters : Map < string , KoaRouter < any , Context > > ;
27+ private readonly router : Router ;
28+ private readonly checkRouters : Map < string , Router > ;
3029 private readonly controllerMeta : HTTPControllerMeta ;
3130 private readonly methodMeta : HTTPMethodMeta ;
3231 private readonly proto : EggPrototype ;
@@ -36,8 +35,8 @@ export class HTTPMethodRegister {
3635 proto : EggPrototype ,
3736 controllerMeta : HTTPControllerMeta ,
3837 methodMeta : HTTPMethodMeta ,
39- router : KoaRouter < any , Context > ,
40- checkRouters : Map < string , KoaRouter < any , Context > > ,
38+ router : Router ,
39+ checkRouters : Map < string , Router > ,
4140 eggContainerFactory : typeof EggContainerFactory ,
4241 ) {
4342 this . proto = proto ;
@@ -133,14 +132,14 @@ export class HTTPMethodRegister {
133132 } ) ;
134133 }
135134
136- private registerToRouter ( router : KoaRouter < any , Context > ) {
135+ private registerToRouter ( router : Router ) {
137136 const routerFunc = router [ this . methodMeta . method . toLowerCase ( ) ] ;
138137 const methodRealPath = this . controllerMeta . getMethodRealPath ( this . methodMeta ) ;
139138 const methodName = this . controllerMeta . getMethodName ( this . methodMeta ) ;
140139 Reflect . apply ( routerFunc , router , [ methodName , methodRealPath , noop ] ) ;
141140 }
142141
143- private checkDuplicateInRouter ( router : KoaRouter < any , Context > ) {
142+ private checkDuplicateInRouter ( router : Router ) {
144143 const methodRealPath = this . controllerMeta . getMethodRealPath ( this . methodMeta ) ;
145144 const matched = router . match ( methodRealPath , this . methodMeta . method ) ;
146145 const methodName = this . controllerMeta . getMethodName ( this . methodMeta ) ;
0 commit comments