Replies: 2 comments 6 replies
-
Some of this could be helped by type-informed compilation. Swift lets you do this: enum Weekday {
case monday, tuesday, /* ... */ saturday, sunday
}
func schedule(appointment: Appointment, for day: Weekday) {
// ...
}
schedule(appointment: wedding, for: .saturday) Note the leading dot -- |
Beta Was this translation helpful? Give feedback.
-
I like the idea of a simple transpilation like this: open enum WeekDay
Monday
Tuesday
↓↓↓
enum WeekDay {
Monday,
Tuesday
}
const { Monday, Tuesday } = WeekDay TypeScript seems to understand that the global On the other hand, I'm not a fan of the word " |
Beta Was this translation helpful? Give feedback.
-
Often I would like the individual identifiers in an enum to "pollute" the outer namespace, e.g.
I would love some declaration like
open enum WeekDay
that would allow dropping the often-redundantWeekDay.
part. (There's lots of ways to do this; use regular enum and just add a bunch of constant definitions immediately after is the most straightforward; I've also seen defining a bunch of disparateSymbol('Monday')
constants and then definingWeekDay
to be the union of all their types.)Beta Was this translation helpful? Give feedback.
All reactions