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

Express related types as discriminated unions #4

Open
eddiesholl opened this issue Jul 7, 2018 · 0 comments
Open

Express related types as discriminated unions #4

eddiesholl opened this issue Jul 7, 2018 · 0 comments

Comments

@eddiesholl
Copy link

eddiesholl commented Jul 7, 2018

Have you had a chance to think about expressing 'base' types as discriminated unions rather than just the straight inheritance model? So for example:

type Expression = EmptyExpression | ArrowFunctionExpression | ...

This would make it amazing for using the types for working with ASTs.

The basic task of working out the relationships shouldn't be too tricky, using interface extensions. But working out which types to express as a union seems like a hard problem. For example, no one is creating a raw Node instance, so that would be fine to express as a union type, but 'middle tier' types might be a bit trickier.

The other piece to it is that any type that is part of a union, needs to define their type parameter as a the explicit type name string, not just of type 'string'. For example,

export interface ReturnStatement {
    type: "ReturnStatement",
    argument?: Expression,
    loc?: SourceLocation,
}
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

1 participant