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

Issue with enums #28

Closed
fairking opened this issue Jul 27, 2020 · 1 comment
Closed

Issue with enums #28

fairking opened this issue Jul 27, 2020 · 1 comment

Comments

@fairking
Copy link

Got the following code:

export enum TicketPriorityEnum {
  'Low' = 'Low',
  'Medium' = 'Medium',
  'High' = 'High',
  'Critical' = 'Critical'
}
...
import { TicketPriorityEnum } from '../../services';
nameof(TicketPriorityEnum)

And the following error:

Error	TS2769	(TS) No overload matches this call.
  Overload 1 of 2, '(selector: (obj: Object) => any, options?: NameofOptions): string', gave the following error.
    Argument of type 'typeof TicketPriorityEnum' is not assignable to parameter of type '(obj: Object) => any'.
      Type 'typeof TicketPriorityEnum' provides no match for the signature '(obj: Object): any'.
  Overload 2 of 2, '(classType: new (...params: any[]) => Object): string', gave the following error.
    Argument of type 'typeof TicketPriorityEnum' is not assignable to parameter of type 'new (...params: any[]) => Object'.
      Type 'typeof TicketPriorityEnum' provides no match for the signature 'new (...params: any[]): Object'.

I guess enums are not supported. Are they?

@IRCraziestTaxi
Copy link
Owner

Sorry I took so long to reply to this. It fell off my radar.

Enums are indeed not supported and, as this lib's nameof is a runtime function, there would be no way to support them. Since all it does is call toString on the class or function passed in, calling toString on an enum yields [object Object], which yields no information about its name, which is really just a variable name as far as JS is concerned.

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

No branches or pull requests

2 participants