From c42bf77644243192a83e1d4f0fee6cb9be2498b3 Mon Sep 17 00:00:00 2001 From: Shigma <1700011071@pku.edu.cn> Date: Fri, 4 Sep 2020 21:55:54 +0800 Subject: [PATCH] feat(core): narrow parsedArgv.session typings --- packages/koishi-core/src/command.ts | 8 ++++++-- packages/koishi-core/src/plugins/validate.ts | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/koishi-core/src/command.ts b/packages/koishi-core/src/command.ts index e36f933683..5af3ee6ec2 100644 --- a/packages/koishi-core/src/command.ts +++ b/packages/koishi-core/src/command.ts @@ -84,7 +84,7 @@ export interface ParsedLine { export interface ParsedArgv extends Partial> { command: Command - session: Session + session: ArgvSession next?: NextFunction } @@ -93,6 +93,10 @@ export interface ExecuteArgv extends Partial { next?: NextFunction } +export interface ArgvSession extends Session { + $argv?: ParsedArgv +} + export interface CommandConfig { /** description */ description?: string @@ -107,7 +111,7 @@ export type FieldCollector, fields: Set) => void) export type CommandAction = - (this: Command, config: ParsedArgv, ...args: string[]) => void | string | Promise + (this: Command, argv: ParsedArgv, ...args: string[]) => void | string | Promise export class Command { config: CommandConfig diff --git a/packages/koishi-core/src/plugins/validate.ts b/packages/koishi-core/src/plugins/validate.ts index 007ba3f524..6e320e7cb0 100644 --- a/packages/koishi-core/src/plugins/validate.ts +++ b/packages/koishi-core/src/plugins/validate.ts @@ -9,9 +9,9 @@ import { Message } from './message' export type UserType = T | ((user: Pick) => T) declare module '../command' { - interface Command { - _checkers: ((session: Session) => string | boolean)[] - before(checker: (session: Session) => string | boolean): this + interface Command { + _checkers: ((session: ArgvSession) => string | boolean)[] + before(checker: (session: ArgvSession) => string | boolean): this getConfig(key: K, session: Session): Exclude any> }