language icon indicating copy to clipboard operation
language copied to clipboard

Support Intersection Types in Dart (e.g., T extends A & B, typedef AB = A & B)

Open tilucasoli opened this issue 7 months ago • 1 comments

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;

tilucasoli avatar May 03 '25 19:05 tilucasoli

See #2709.

mmcdon20 avatar May 03 '25 20:05 mmcdon20