@@ -213,13 +213,16 @@ interface Constructable<T> {
213
213
new ( ...args : any [ ] ) : T ;
214
214
}
215
215
216
- interface Mapper < Target > {
216
+ export interface Mapper < Target > {
217
217
< Source > ( source : Source [ ] ) : Target [ ] ;
218
218
< Source > ( source : Source ) : Target ;
219
219
}
220
220
221
221
function transformItems < T , TSchema extends Schema < T > > ( schema : TSchema ) : Mapper < { [ P in keyof TSchema ] : any } > ;
222
- function transformItems < T , TSchema extends Schema < T > > ( schema : TSchema , type : Constructable < T > ) : Mapper < { [ P in keyof TSchema ] : any } > ;
222
+ function transformItems < T , TSchema extends Schema < T > > (
223
+ schema : TSchema ,
224
+ type : Constructable < T >
225
+ ) : Mapper < { [ P in keyof TSchema ] : any } > ;
223
226
224
227
function transformItems < T , TSchema extends Schema < T > > ( schema : TSchema , type ?: Constructable < T > ) {
225
228
function mapper ( source : any ) : any {
@@ -293,8 +296,16 @@ export function morphism<Target>(schema: Schema<Target>): Mapper<Target>; // mor
293
296
export function morphism ( schema : Schema < any > , items : null ) : undefined ; // Reflects a specific use case where Morphism({}, null) return undefined
294
297
export function morphism ( schema : null , items : { } ) : undefined ; // Reflects a specific use case where Morphism(null, {}) return undefined
295
298
296
- export function morphism < Target , Source > ( schema : Schema < Target > , items : null , type : Constructable < Target > ) : Mapper < Target > ; // morphism({}, null, T) => mapper(S) => T
297
- export function morphism < Target , Source > ( schema : Schema < Target > , items : Source [ ] , type : Constructable < Target > ) : Target [ ] ; // morphism({}, [], T) => T[]
299
+ export function morphism < Target , Source > (
300
+ schema : Schema < Target > ,
301
+ items : null ,
302
+ type : Constructable < Target >
303
+ ) : Mapper < Target > ; // morphism({}, null, T) => mapper(S) => T
304
+ export function morphism < Target , Source > (
305
+ schema : Schema < Target > ,
306
+ items : Source [ ] ,
307
+ type : Constructable < Target >
308
+ ) : Target [ ] ; // morphism({}, [], T) => T[]
298
309
export function morphism < Target , Source > ( schema : Schema < Target > , items : Source , type : Constructable < Target > ) : Target ; // morphism({}, {}, T) => T
299
310
300
311
export function morphism < Target , Source > ( schema : Schema < Target > , items ?: Source , type ?: Constructable < Target > ) {
@@ -439,7 +450,9 @@ export class MorphismRegistry implements IMorphismRegistry {
439
450
if ( ! schema ) {
440
451
throw new Error ( `The schema must be an Object. Found ${ schema } ` ) ;
441
452
} else if ( ! this . exists ( type ) ) {
442
- throw new Error ( `The type ${ type . name } is not registered. Register it using \`Mophism.register(${ type . name } , schema)\`` ) ;
453
+ throw new Error (
454
+ `The type ${ type . name } is not registered. Register it using \`Mophism.register(${ type . name } , schema)\``
455
+ ) ;
443
456
} else {
444
457
let fn = morphism ( schema , null , type ) ;
445
458
this . _registry . cache . set ( type , fn ) ;
0 commit comments