Skip to content

Add extensions on non-function typedefs #2284

Closed
@sebastianbuechler

Description

@sebastianbuechler

In the original issue for introducing typedefs for non-function types, I saw questions about how extensions would work with this new feature. However, it seems that this did not make the cut yet.

The purpose of this could be something like this to parse more conveniently json lists of objects:

typedef Cars= List<Car>;

extension on Cars{
  Cars fromJson(List json) {
    final Cars cars = [];
    for (final car in json) {
      cars.add(Car.fromJson(car as Map<String, dynamic>));
    }

    return cars;
  }
}

Original comment:
That's how it works already with extensions on functions, so likely.

typedef VoidCallback = void Function();

extension on VoidCallback {
  void foo() {}
}

void main() {
  void Function() test = () {};

  test.foo();
}

Originally posted by @rrousselGit in #65 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions