-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
In TypeScript, sometimes one wants to define an enum based on another enum(s), whose common members may or may not be found to be nominally distinct. Consider these simple examples:
Existing workaround 1:
enum Foo {
A = 'a',
}
enum Bar {
B = 'b',
}
const FooBar = {
...Foo,
...Bar,
// Additional members can be defined here
};
type FooBar = Foo | Bar;
// FooBar.A is assignable to Foo.A - not nominally distinctExisting non-solution:
const FooBar = {
A = Foo.A,
B = Foo.B,
};
// May ensure that all members of FooBar are members of Foo and Bar, but not the converse.Potential first-class syntax 1:
enum FooBar {
...Foo,
...Bar,
// Additional members can be defined here
}Potential first-class syntax 2:
enum FooBar extends Foo, Bar {
// Additional members can be defined here
} // introduce multiple inheritance syntax to the languagePotential first-class syntax 3:
enum FooBar extends Foo { // Only allow single inheritance
B = Bar.B,
}Ginden
Metadata
Metadata
Assignees
Labels
No labels