Skip to content

How to use typedef inside a class with Generics? #4151

Closed as not planned
Closed as not planned
@tolotrasamuel

Description

@tolotrasamuel

How to use typedef with generics ?

How to use typedef inside a class ?

I have the following class.

class Bar<T> {
  void bar() {
    print(T);
  }
}

class Foo<T> {
  Bar<T> merge(Bar<T> a, Bar<T> b, Bar<T> c) {
    a.bar();
    b.bar();
    return c;
  }
}

To avoid repeating Bar<T> I want to use typedef

class Foo<T> {

  typedef Baz = Bar<T>;
  
  Baz merge(Baz a, Baz b, Baz c) {
    a.bar();
    b.bar();
    return c;
  }
}

But this is obviously not working with the current Dart. Is it supported ? I know I create an alias of the Bar to a shorter string but this does not remove the generic, the problem is in reality, the generic has several nested class like Foo<Bar<Baz<Foz<Boz<T>>>>

Metadata

Metadata

Assignees

No one assigned

    Labels

    requestRequests to resolve a particular developer problemstate-duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions