From e9855809c748d4afebb3bb63f99c72fdf65a997a Mon Sep 17 00:00:00 2001 From: brick Date: Mon, 4 Jun 2018 15:16:38 +0800 Subject: [PATCH 1/2] feat: add index.d.ts --- index.d.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..217c450 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,22 @@ +interface CheckHandlerFunc { + (rule: any, value: any): string; +} + +interface ValidateError { + code: string; + field: string; + message: string; +} + +declare module 'egg' { + export interface Application { + validator: { + addRule: (type: string, check: RegExp | CheckHandlerFunc) => void; + validate: (rules: any, data: any) => ValidateError[]; + }; + } + + export interface Context { + validate: (rules: any, data: any) => void; + } +} From 610847a86985bad7b6f9b90332699b99aa9976dc Mon Sep 17 00:00:00 2001 From: Brick Date: Thu, 21 Jun 2018 16:07:41 +0800 Subject: [PATCH 2/2] fix: field can be undefined ValidatorError.field can be undefined, add ? modifier --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 217c450..0d86b3b 100644 --- a/index.d.ts +++ b/index.d.ts @@ -4,7 +4,7 @@ interface CheckHandlerFunc { interface ValidateError { code: string; - field: string; + field?: string; message: string; }