Skip to content

Commit

Permalink
fix: remove template on use MiddlewareFunc
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Jan 2, 2025
1 parent 5607450 commit f4315d9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export class Application extends Emitter {
/**
* Use the given middleware `fn`.
*/
use<T = Context>(fn: MiddlewareFunc<T>) {
use(fn: MiddlewareFunc) {
if (typeof fn !== 'function') throw new TypeError('middleware must be a function!');
const name = fn._name || fn.name || '-';
if (isGeneratorFunction(fn)) {
Expand All @@ -160,7 +160,7 @@ export class Application extends Emitter {
'https://github.com/koajs/koa/blob/master/docs/migration.md');
}
debug('use %o #%d', name, this.middleware.length);
this.middleware.push(fn as MiddlewareFunc<Context>);
this.middleware.push(fn);
return this;
}

Expand Down
4 changes: 2 additions & 2 deletions test/application/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ describe('app.context', () => {
}

const app = new MyApp();
app.use((ctx: MyContext) => {
ctx.body = `hello, ${ctx.getMsg()}`;
app.use(ctx => {
ctx.body = `hello, ${(ctx as MyContext).getMsg()}`;
});

it('should work with sub class', () => {
Expand Down

0 comments on commit f4315d9

Please sign in to comment.