dsherret / ts-nameof

nameof in TypeScript
MIT License
492 stars 23 forks source link

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

Open hanvyj opened 4 years ago

hanvyj commented 4 years ago

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"?

dsherret commented 4 years ago

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