Skip to content

Commit

Permalink
fix: IMiddleware type is incompatible (#3419)
Browse files Browse the repository at this point in the history
  • Loading branch information
whxaxes authored Jan 24, 2019
1 parent b3256b5 commit 43f2e3c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ declare module 'egg' {
headers: { [key: string]: string };
}

export interface Router extends KoaRouter {
export interface Router extends KoaRouter<any, Context> {
/**
* restful router api
*/
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/apps/app-ts/app/middleware/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import TestMiddleware from './test';

declare module 'egg' {
interface IMiddleware {
test: typeof TestMiddleware;
}
}
8 changes: 8 additions & 0 deletions test/fixtures/apps/app-ts/app/middleware/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Context } from 'egg';

export default () => {
return async (ctx: Context, next: () => Promise<any>) => {
ctx.locals.url = ctx.url;
await next();
};
}
1 change: 1 addition & 0 deletions test/fixtures/apps/app-ts/app/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Application } from 'egg';

export default (app: Application) => {
const controller = app.controller;
app.router.get('/test', app.middleware.test(), controller.foo.getData);
app.get('/foo', controller.foo.getData);
app.post('/', controller.foo.getData);
}
8 changes: 8 additions & 0 deletions test/ts/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,13 @@ describe('test/ts/index.test.js', () => {
.expect({ env: 'unittest' })
.end(done);
});

it('controller of app.router run ok', done => {
request(app.callback())
.get('/test')
.expect(200)
.expect({ env: 'unittest' })
.end(done);
});
});
});

0 comments on commit 43f2e3c

Please sign in to comment.