Generics
- Generics customize the type annotations of properties of a class
- The generics is defined with angle brackets
class HoldNumber {
data: number;
}
class HoldString {
data: string;
}
// Generics allows the customization of the type! TypeOfData is usually defined as T
class HoldAnything<TypeOfData> {
data: TypeOfData;
}
// Instantiation
const holdNumber = new HoldAnything<number>();
holdNumber.data = 123;
const holdString = new HoldAnything<string>();
holdString.data = 'hey!';
interface Event {
subject: Subjects;
data: any;
}
abstract class Listener<T extends Event> {
abstract subject: T['subject'];
abstract queueGroupName: string;
abstract onMessage(data: T['data'], msg: Message): void;
private client: Stan;
}