language
language copied to clipboard
Support Intersection Types in Dart (e.g., T extends A & B, typedef AB = A & B)
Problem
Dart currently does not support intersection types — types that must simultaneously conform to multiple protocols.
For example:
abstract class A {}
abstract class B {}
mixin MyMixin<T extends A & B> {}
Or:
typedef AB = A & B;
Proposed Feature
Allow the use of intersection types in:
Generic constraints:
mixin MyMixin<T extends A & B> {}
Flutter Use Case
In Flutter, mixins often rely on both StatefulWidget and another interface or capability:
mixin MyBehavior<T extends StatefulWidget & MyInterface> on State<T> {}
Type aliases
typedef AB = A & B;
See #2709.