Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hanvyj opened this issue Jun 18, 2020 · 1 comment
Open

Comments

@hanvyj
Copy link

hanvyj commented Jun 18, 2020

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 hanvyj changed the title Names on prototypes Accessing the full name of properties on class (without a '.prototype') Jun 18, 2020
@dsherret
Copy link
Owner

dsherret commented Jun 30, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants