-
Notifications
You must be signed in to change notification settings - Fork 33
[interop] Add Support for Enums #404
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
base: main
Are you sure you want to change the base?
Conversation
@@ -47,6 +58,53 @@ class UnionType extends Type { | |||
String? get name => null; | |||
} | |||
|
|||
class HomogenousUnionType<T extends LiteralType, D extends Declaration> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at declaration
, if this is always going to be an Enum
, can we call it HomogenousEnumType
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe UnionEnumType
? I feel maybe calling it HomogenousEnumType
would confuse it as being directly related to an EnumDeclaration
when it only is in reference. (I might be totally wrong on this however, but what do you think?)
Closes #393
This PR adds support for enumerations in the Dart JS Interop Interface Gen project.
Enums in TS with the
enum
keyword are mapped to (constant) Dart extension types with the values being static properties.Therefore:
Turns into:
This enum pattern is used to represent TS Syntax Kinds in the generator.
Although the vast majority of enums declared with the
enum
keyword are homogenous with defined number or string values:JSAny
This PR also supports homogenous union types as enums (i.e
"north" | "south" | "east" | "west"
), translating them to become enum declarations.