From 401655b49e263fc28fec7f9251b330590e776e8d Mon Sep 17 00:00:00 2001 From: Shigma <1700011071@pku.edu.cn> Date: Mon, 23 Aug 2021 20:43:15 +0800 Subject: [PATCH] fix(core): enhance typings for async hooks, fix #363 --- packages/koishi-core/src/context.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/koishi-core/src/context.ts b/packages/koishi-core/src/context.ts index 3b302e219c..3041d40aa2 100644 --- a/packages/koishi-core/src/context.ts +++ b/packages/koishi-core/src/context.ts @@ -11,7 +11,7 @@ import Router from '@koa/router' export type NextFunction = (next?: NextFunction) => Promise export type Middleware = (session: Session, next: NextFunction) => any export type Promisify = T extends Promise ? T : Promise -export type Awaitable = T extends Promise ? T : T | Promise +export type Awaitable = [T] extends [Promise] ? T : T | Promise export type Await = T extends Promise ? U : T export type Disposable = () => void @@ -380,7 +380,7 @@ export class Context { const dispose = this.on(name, function (...args: any[]) { dispose() return listener.apply(this, args) - } as any, prepend) + }, prepend) return dispose }