How to get enum declaration from type
See original GitHub issueHi, i see that i can get the enum members -
const members = enumDeclaration.getMembers();
but i have the type, how can i get the type declaration to get the members?
export enum Role {
admin = "admin",
user = "user"
}
export class User {
role: Role;
}
i looping other user properties and build my ajv scheme -
export const getParamSchema = (type: Type) => {
if (type.isEnumLiteral()) {
schema.type = "string";
schema.enum = [];// here i want to add the enum members..
}
}
thanks.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Handbook - Enums - TypeScript
Above, we have a numeric enum where Up is initialized with 1 . ... is simple: just access any member as a property...
Read more >Enumeration declaration - cppreference.com
An enumeration is a distinct type whose value is restricted to a range of values (see below for details), which may include several ......
Read more >Enum in TypeScript - TutorialsTeacher
In simple words, enums allow us to declare a set of named constants i.e. a collection of related values that can be numeric...
Read more >Enumeration (or enum) in C - GeeksforGeeks
The keyword 'enum' is used to declare new enumeration types in C and ... All unassigned names get value as value of previous...
Read more >How to get names of enum entries? - Stack Overflow
In JS enum is an object of [value]: name so you can get all values like that Object.keys(enum) , all names Object.values(enum) and...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@yantrab now that #916 is implemented you should be able to do:
@dsherret forgive me for potentially hijacking this question, I feel like it’s very similar to my question. Happy to open a new issue if that’s better!
My question: is there a way to add enum or union members? I have the following:
and I can see the literal values of my union type
Foo
. Great. Now, what’s the way for me to add a new element to the union'd'
say?(I see that object expressions have
addPropertyAssignment
for example, and wondering if there’s an equivalent for unions?)