Re:Show HN: I made a 2D game engine in Dart
by nmfisher on Wednesday July 02, 2025 @11:12PM
(#44451294)
I'm a heavy user of exhaustive pattern matching with sealed classes, definitely a great feature. You can achieve the same outcome as union types, but it's a lot more leg work, e.g.:
```
sealed class MyParam {}
class Bar extends MyParam { String val; }
class Baz extends MyParam { int val; }
void foo(MyParam param) {
switch(myParam) {
case Baz(val: final val):
case Bar(val: final val):
}
}
```compared to:
```
void foo(Bar | Baz myVar) {
switch(myVar) {
case Bar:
case Baz:
}
}
```I hadn't seen the extension_type_unions package, though, I'll check it out.
Another user hinted at this package https://pub.dev/packages/extension_type_unions, have you seen it before?
Also it's worth noting that sum types can be achieved with Dart 3!