11import Signature from '../internal/types/Signature'
22import MessagesConfig from '../internal/types/MessagesConfig'
33import MessageInitializer from '../internal/types/MessageInitializer'
4- import MessageCreator from '../internal/types/MessageCreator'
54import buildMessageCreator from '../internal/buildMessageCreator' ;
65
76// --- defineMessages -----------------------------------------------
87
98function defineMessages < T extends MessagesConfig > ( prefix : string , config : T ) :
10- { [ K in keyof T ] : MessageCreator < Arguments < any , T [ K ] > , Payload < T [ K ] > , Meta < T [ K ] > > }
9+ { [ K in keyof T ] : MessageCreatorOf < T [ K ] > & { type : string } }
1110
1211function defineMessages < T extends MessagesConfig > ( config : T ) :
13- { [ K in keyof T ] : MessageCreator < Arguments < any , T [ K ] > , Payload < T [ K ] > , Meta < T [ K ] > > }
12+ { [ K in keyof T ] : MessageCreatorOf < T [ K ] > & { type : string } }
1413
1514function defineMessages ( arg1 : any , arg2 ?: any ) : any {
1615 const
@@ -32,28 +31,28 @@ function defineMessages(arg1: any, arg2?: any): any {
3231
3332// --- locals -------------------------------------------------------
3433
35- type Func < A extends any [ ] , R > = ( ... args : A ) => R
36-
37- type Arguments < A extends any [ ] , I extends MessageInitializer < any > >
38- = I extends Func < A , any >
39- ? Signature < I >
40- : ( I extends { payload : Func < A , any > }
41- ? Signature < I [ ' payload' ] >
42- : [ ] )
43-
44- type Payload < I extends MessageInitializer < any > >
45- = I extends Func < any , any >
46- ? ReturnType < I >
47- : ( I extends { payload : Func < any , any > }
48- ? ReturnType < I [ 'payload' ] >
49- : any )
50-
51- type Meta < I extends MessageInitializer < any > >
52- = I extends Func < any , any >
53- ? ReturnType < I >
54- : ( I extends { meta : Func < any , any > }
55- ? ReturnType < I [ 'meta' ] >
56- : any )
34+ type MessageCreatorOf < T > =
35+ T extends {
36+ payload : ( ... args : infer A ) => infer P ,
37+ meta : ( ... args : infer A ) => infer M ,
38+ validate ?: ( ... args : infer A ) => boolean | null | Error
39+ }
40+ ? ( ... args : A ) => { type : string , payload : P , meta : M }
41+ : T extends {
42+ meta : ( ... args : infer A ) => infer M ,
43+ validate ?: ( ... args : infer A ) => boolean | null | Error
44+ }
45+ ? ( ... args : A ) => { type : string , meta : M }
46+ : T extends {
47+ payload : ( ... args : infer A ) => infer P ,
48+ validate ?: ( ... args : infer A ) => boolean | null | Error
49+ }
50+ ? ( ... args : A ) => { type : string , payload : P }
51+ : T extends ( ... args : infer A ) => infer P
52+ ? ( ... args : A ) => { type : string , payload : P }
53+ : T extends { }
54+ ? ( ) => { type : string }
55+ : never
5756
5857// --- exports ------------------------------------------------------
5958
0 commit comments