Guest User

Untitled

a guest
May 23rd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. const name: string = nameof(Console.log);
  2. // 'name' is now equal to "log"
  3.  
  4. nameof(console); // => "console"
  5. nameof(console.log); // => "log"
  6. nameof<MyInterface>(); // => "MyInterface"
  7. nameof<MyNamespace.MyInnerInterface>(); // => "MyInnerInterface"
  8.  
  9. const nameof = <T>(name: keyof T) => name;
  10.  
  11. interface Person {
  12. firstName: string;
  13. lastName: string;
  14. }
  15.  
  16. const personName1 = nameof<Person>("firstName"); // => "firstName"
  17. const personName2 = nameof<Person>("noName"); // => compile time error
Add Comment
Please, Sign In to add comment