Parses a class name or a dot-separated property name from a lambda expression and provides some level of type safety using type parameters.
npm install ts-simple-nameof``ts`
// Returns "posts".
nameof
// Returns "user.posts".
nameof
) is used. Therefore, this method strips out ! and ? operators from the parsed property name.`ts
class Parent {
public child?: Child;
}// Throws error "Object may be 'null'." with strict null checking enabled.
nameof(p => p.child.prop);
// Mitigates error and returns "child.prop".
nameof(p => p.child!.prop);
`Class Names
ts-simple-nameof now also returns the name of a class.`ts
// Returns "User".
nameof(User);
`Installation
To add ts-simple-nameof to your project using NPM:`
npm install --save ts-simple-nameof
``