SHARE
TWEET

Untitled

a guest Jun 20th, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. interface SerializableClass {
  2.     new (...a:any[]): any;
  3.     readonly className: string;
  4. }
  5. interface Serialised<T extends SerializableClass> {
  6.     className: T['className']; // error
  7.     value: InstanceType<T>;
  8. }
  9.  
  10. class Ok {
  11.     static readonly className = "Ok"
  12. }
  13.  
  14. let o: Serialised<typeof Ok> = {
  15.     className: "Ok",
  16.     value: new Ok()
  17. }
  18.  
  19. let o2: Serialised<typeof Ok> = {
  20.     className: "Okk", //err
  21.     value: new Ok()
  22. }
  23.  
  24. class Bad{}
  25. let o3: Serialised<typeof Bad> //err Type 'typeof Bad' does not satisfy the constraint 'SerializableClass'.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top