|
|
|
|
|
by Alifatisk
350 days ago
|
|
When coming from TS to Dart, the lack of union types was a huge bummer. But I saw a discussion somewhere that you can achieve something close with sealed classes to model union types combined with exhaustive pattern matching, but Idk. 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! |
|
```
sealed class MyParam {}
class Bar extends MyParam { String val; }
class Baz extends MyParam { int val; }
void foo(MyParam param) {
} ```compared to:
```
void foo(Bar | Baz myVar) {
} ```I hadn't seen the extension_type_unions package, though, I'll check it out.