ts-nameof
ts-nameof copied to clipboard
Accessing the full name of properties on class (without a '.prototype')
I'm using the class/function names of a generated API and ts-nameof
looks like a great way to make this more compile safe.
My API is a class, for example UserApi
so has to be initialised with new. Used like new UserApi().getUser()
. I want something like "UserApi.getUser". Because it's a class, I can't use nameof
like: UserApi.getUser
, I have to do UserApi.prototype.getUser
. This however gives "UserApi.prototype.getUser".
Is there any way to get just "UserApi.getUser", without the "prototype"?
@hanvyj sorry for my delay. I don't think there's an easy way of doing this right now. I believe only the following works:
`${nameof<UserApi>()}.${nameof<UserApi>(u => u.getUser)}`
I'll try to think of a solution that would work. Maybe nameof.full<UserApi["getUser"]>
would go to UserApi.getUser
... I'm not sure (related to #102)