Simplify types
This commit is contained in:
parent
6eddb4834b
commit
ba8b1a29fd
30 changed files with 52 additions and 76 deletions
|
|
@ -1,8 +0,0 @@
|
|||
import { v4 } from 'uuid';
|
||||
import { Id } from './identity';
|
||||
|
||||
export class IdentityManager {
|
||||
public static generateId(): Id {
|
||||
return v4();
|
||||
}
|
||||
}
|
||||
14
shared/src/transport/type-to-base-type.ts
Normal file
14
shared/src/transport/type-to-base-type.ts
Normal 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;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue