Skip to content

Commit c429af4

Browse files
committed
feat: Add type on Morphism registry
1 parent fc20354 commit c429af4

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/morphism.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -327,37 +327,37 @@ export interface IMorphismRegistry {
327327
* @param {Object} data Input data to transform
328328
*
329329
*/
330-
map<TTarget>(type: TTarget): Mapper<TTarget>;
331-
map<TTarget, TSource>(type: Constructable<TTarget>, data: TSource[]): TTarget[];
332-
map<TTarget, TSource>(type: Constructable<TTarget>, data: TSource): TTarget;
330+
map<Target>(type: Target): Mapper<Target>;
331+
map<Target, Source>(type: Constructable<Target>, data: Source[]): Target[];
332+
map<Target, Source>(type: Constructable<Target>, data: Source): Target;
333333
/**
334334
* Get a specific mapping function for the provided Class
335335
*
336336
* @param {Type} type Class Type of the ouput Data
337337
*
338338
*/
339-
getMapper: (type: any) => any;
339+
getMapper<Target>(type: Constructable<Target>): Mapper<Target>;
340340
/**
341341
* Set a schema for a specific Class Type
342342
*
343343
* @param {Type} type Class Type of the ouput Data
344344
* @param {Schema} schema Class Type of the ouput Data
345345
*
346346
*/
347-
setMapper: (type: any, schema: Schema) => any;
347+
setMapper<Target, TSchema extends Schema>(type: Constructable<Target>, schema: TSchema): Mapper<Target>;
348348
/**
349349
* Delete a registered schema associated to a Class
350350
*
351351
* @param type ES6 Class Type of the ouput Data
352352
*
353353
*/
354-
deleteMapper: (type: any) => any;
354+
deleteMapper<Target>(type: Constructable<Target>): any;
355355
/**
356356
* Check if a schema has already been registered for this type
357357
*
358358
* @param {*} type
359359
*/
360-
exists: (type: any) => boolean;
360+
exists<Target>(type: Target): boolean;
361361
/**
362362
* Get the list of the mapping functions registered
363363
*
@@ -419,7 +419,7 @@ export class MorphismRegistry implements IMorphismRegistry {
419419
* @param {Type} type Class Type of the ouput Data
420420
*
421421
*/
422-
getMapper(type: any) {
422+
getMapper<Target>(type: Constructable<Target>) {
423423
return this._registry.cache.get(type);
424424
}
425425
/**
@@ -429,7 +429,7 @@ export class MorphismRegistry implements IMorphismRegistry {
429429
* @param {Schema} schema Class Type of the ouput Data
430430
*
431431
*/
432-
setMapper(type: any, schema: Schema) {
432+
setMapper<Target>(type: Constructable<Target>, schema: Schema) {
433433
if (!schema) {
434434
throw new Error(`The schema must be an Object. Found ${schema}`);
435435
} else if (!this.exists(type)) {

0 commit comments

Comments
 (0)