ts-nameof icon indicating copy to clipboard operation
ts-nameof copied to clipboard

Accessing the full name of properties on class (without a '.prototype')

Open hanvyj opened this issue 4 years ago • 1 comments

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 avatar Jun 18 '20 14:06 hanvyj

@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)

dsherret avatar Jun 30 '20 18:06 dsherret