From f4315d9cebc594bacfaa994f4d6ac548c97c57b8 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Thu, 2 Jan 2025 19:00:22 +0800 Subject: [PATCH] fix: remove template on use MiddlewareFunc --- src/application.ts | 4 ++-- test/application/context.test.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/application.ts b/src/application.ts index 3025d836e..88bbe0da7 100644 --- a/src/application.ts +++ b/src/application.ts @@ -151,7 +151,7 @@ export class Application extends Emitter { /** * Use the given middleware `fn`. */ - use(fn: MiddlewareFunc) { + use(fn: MiddlewareFunc) { if (typeof fn !== 'function') throw new TypeError('middleware must be a function!'); const name = fn._name || fn.name || '-'; if (isGeneratorFunction(fn)) { @@ -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); + this.middleware.push(fn); return this; } diff --git a/test/application/context.test.ts b/test/application/context.test.ts index 4078f5da1..908199872 100644 --- a/test/application/context.test.ts +++ b/test/application/context.test.ts @@ -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', () => {