Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tilucasoli opened this issue May 3, 2025 · 1 comment
Labels
feature Proposed language feature that solves one or more problems

Comments

@tilucasoli
Copy link

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 tilucasoli added the feature Proposed language feature that solves one or more problems label May 3, 2025
@mmcdon20
Copy link

mmcdon20 commented May 3, 2025

See #2709.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Proposed language feature that solves one or more problems
Projects
None yet
Development

No branches or pull requests

2 participants