Simplify types

This commit is contained in:
schmelczerandras 2020-10-06 14:08:43 +02:00
parent 6eddb4834b
commit ba8b1a29fd
30 changed files with 52 additions and 76 deletions

View file

@ -1,8 +0,0 @@
import { v4 } from 'uuid';
import { Id } from './identity';
export class IdentityManager {
public static generateId(): Id {
return v4();
}
}

View file

@ -0,0 +1,14 @@
export const typeToBaseType = <T extends { new(...args: any[]): {} }>(
constructor: T
) => {
const parent = constructor;
return class extends constructor {
public static get type(): string {
return Object.getPrototypeOf((parent as any).prototype).constructor.name;
}
public get type(): string {
return Object.getPrototypeOf((parent as any).prototype).constructor.name;
}
};
};

View file

@ -1,11 +1,9 @@
/**
* static type: string must be implemented
* @param constructor
*/
export const typed = <T extends { new (...args: any[]): {} }>(constructor: T) => {
return class extends constructor {
public get type(): string {
return (this as any).constructor.type;
}
};
};
export abstract class Typed {
public static get type(): string {
return (this as any).name;
}
public get type(): string {
return (this as any).constructor.name;
}
}