@@ -17,31 +17,22 @@ import { hasOwn, isFunction } from '../type'
17
17
interface SchemaType {
18
18
rules : Record < string , any > | null
19
19
_messages : Record < string , any >
20
- define ( descriptor : Record < string , any > ) : void
21
- messages ( messages ?: Record < string , any > ) : Record < string , any >
22
- getSeries ( options : any , source : any , source_ : any ) : Record < string , any >
23
- mergeMessage ( options : any ) : void
24
- validate ( source_ : any , o ?: any , oc ?: Function ) : Promise < any >
25
- getValidationMethod ( rule : any ) : any
26
- getType ( rule : any ) : string
20
+ define : ( descriptor : Record < string , any > ) => void
21
+ messages : ( messages ?: Record < string , any > ) => Record < string , any >
22
+ getSeries : ( options : any , source : any , source_ : any ) => Record < string , any >
23
+ mergeMessage : ( options : any ) => void
24
+ validate : ( source_ : any , o ?: any , oc ?: Function ) => Promise < any >
25
+ getValidationMethod : ( rule : any ) => any
26
+ getType : ( rule : any ) => string
27
27
}
28
28
29
- function Schema ( this : SchemaType , descriptor : Record < string , any > , translate ?: any ) {
30
- Schema . getDefaultMessage = ( trans ?: any ) => {
31
- // 返回一个默认消息对象而不是undefined
32
- return trans ? { ...trans } : ( { } as Record < string , any > )
33
- }
34
-
35
- Schema . getSystemMessage = ( trans ?: any ) => {
36
- return Schema . getDefaultMessage ( trans )
37
- }
38
-
29
+ function Schema ( descriptor : Record < string , any > , translate ?: any ) {
30
+ Schema . getSystemMessage = ( ) => Schema . getDefaultMessage ( translate )
39
31
Schema . messages = Schema . getSystemMessage ( translate )
40
32
Schema . systemMessages = Schema . messages
41
-
42
- this . rules = null
43
- this . _messages = Schema . systemMessages
44
- this . define ( descriptor )
33
+ ; ( this as SchemaType ) . rules = null
34
+ ; ( this as SchemaType ) . _messages = Schema . systemMessages
35
+ ; ( this as SchemaType ) . define ( descriptor )
45
36
}
46
37
47
38
/**
@@ -225,8 +216,7 @@ const asyncCallback =
225
216
Schema . prototype = {
226
217
messages ( messages ) {
227
218
if ( messages ) {
228
- const systemMessages = Schema . getSystemMessage ( ) || { }
229
- this . _messages = deepMerge ( systemMessages , messages )
219
+ this . _messages = deepMerge ( Schema . getSystemMessage ( ) , messages )
230
220
}
231
221
232
222
return this . _messages
0 commit comments