Guest User

Untitled

a guest
May 31st, 2019
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. abstract class AbstractEvent<T> {
  2.     public constructor(data: T) {
  3.         for (const key in data) {
  4.             (this as any)[key] = data[key];
  5.         }
  6.     }
  7. }
  8.  
  9. class PackCreatedEvent extends AbstractEvent<PackCreatedEvent> {
  10.     public readonly id: string;
  11.     public readonly title: string;
  12. }
  13.  
  14. const packCreatedEvent1 = new PackCreatedEvent({
  15.     id: 'x',
  16.     title: 'y',
  17. });
  18.  
  19. const packCreatedEvent2 = new PackCreatedEvent({
  20.     id: 'x',
  21.     title: 'y',
  22.  
  23.     // Causes error as desired
  24.     foo: 'test',
  25. });
Advertisement
Add Comment
Please, Sign In to add comment