Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const name: string = nameof(Console.log);
- // 'name' is now equal to "log"
- nameof(console); // => "console"
- nameof(console.log); // => "log"
- nameof<MyInterface>(); // => "MyInterface"
- nameof<MyNamespace.MyInnerInterface>(); // => "MyInnerInterface"
- const nameof = <T>(name: keyof T) => name;
- interface Person {
- firstName: string;
- lastName: string;
- }
- const personName1 = nameof<Person>("firstName"); // => "firstName"
- const personName2 = nameof<Person>("noName"); // => compile time error
Add Comment
Please, Sign In to add comment