Skip to content

Commit

Permalink
fix(types): use koa['Context'] instead of egg['Context'] as typeof Ko…
Browse files Browse the repository at this point in the history
…aMiddleware
  • Loading branch information
waitingsong committed Jul 9, 2019
1 parent 8fbf356 commit c438f0d
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions packages/midway-decorator/src/interface.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {Context} from 'egg';
import {Context} from 'koa';

export type KoaMiddleware = (context: Context, next: () => Promise<any>) => void;
export type KoaMiddleware <T extends any = Context> = (context: T, next: () => Promise<any>) => void;
export type MiddlewareParamArray <T extends any = Context> = Array<string | KoaMiddleware<T>>
6 changes: 3 additions & 3 deletions packages/midway-decorator/src/web/controller.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { saveClassMetadata, saveModule, scope, ScopeEnum } from 'injection';
import { CONTROLLER_KEY } from '../constant';
import { KoaMiddleware } from '../interface';
import { MiddlewareParamArray } from '../interface';

export interface ControllerOption {
prefix: string;
routerOptions: {
sensitive?: boolean;
middleware?: Array<string | KoaMiddleware>
middleware?: MiddlewareParamArray
};
}

export function controller(prefix: string, routerOptions: {
sensitive?: boolean,
middleware?: Array<string | KoaMiddleware>
middleware?: MiddlewareParamArray
} = {middleware: [], sensitive: true}
): ClassDecorator {
return (target: any) => {
Expand Down
3 changes: 1 addition & 2 deletions packages/midway-decorator/src/web/requestMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
*/
import { attachClassMetadata } from 'injection';
import { WEB_ROUTER_KEY } from '../constant';
import { KoaMiddleware } from '../interface';
import { MiddlewareParamArray } from '../interface';

export type MiddlewareParamArray = Array<string | KoaMiddleware>

export interface RouterOption {
path?: string;
Expand Down
1 change: 1 addition & 0 deletions packages/midway-web/src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {EggLoaderOptions} from 'egg-core';
import {IApplicationContext} from 'injection';
import {KoaMiddleware} from '@midwayjs/decorator';


export interface WebMiddleware {
resolve(): KoaMiddleware;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/midway-web/src/loader/webLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export class MidwayWebLoader extends EggLoader {
for (const webRouter of webRouterInfo) {
// get middleware
const middlewares2: MiddlewareParamArray | void = webRouter.middleware;
const methodMiddlwares = [];
const methodMiddlwares: KoaMiddleware[] = [];

await this.handlerWebMiddleware(middlewares2, (middlewareImpl: KoaMiddleware) => {
methodMiddlwares.push(middlewareImpl);
Expand Down

0 comments on commit c438f0d

Please sign in to comment.