Advertisement
Anatolyukropov

Key array from TS interface

Oct 1st, 2020
2,414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class MyTableClass {
  2.     // list the propeties here, ONLY WRITTEN ONCE
  3.     constructor(
  4.         readonly id?: string,
  5.         readonly title?: string,
  6.         readonly isDeleted?: boolean,
  7.     ) {}
  8. }
  9.  
  10. // This is the pure interface version, to be used/exported
  11. interface IMyTable extends MyTableClass { };
  12.  
  13. type MyTablePropsArray = Array<keyof IMyTable>;
  14.  
  15. console.log(Object.keys(new MyTableClass()));  // prints out  ["id", "title", "isDeleted"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement