Skip to content
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

Is injectable support class with Type Parameter ? #478

Open
azizarc88 opened this issue Sep 20, 2024 · 0 comments
Open

Is injectable support class with Type Parameter ? #478

azizarc88 opened this issue Sep 20, 2024 · 0 comments

Comments

@azizarc88
Copy link

azizarc88 commented Sep 20, 2024

Heres the example

abstract class ExtendedClass {}

class FirstClasFromExtendedClass extends ExtendedClass {}

class SecondClasFromExtendedClass extends ExtendedClass {}

@Injectable()
class MainClass<T extends ExtendedClass> {
  /// can be either
  ///   - FirstClasFromExtendedClass
  ///   - SecondClasFromExtendedClass
  final T extendedClass;

  @factoryMethod
  static MainClass<FirstClasFromExtendedClass> createFirst(
          FirstClasFromExtendedClass extendedClass) =>
      MainClass(extendedClass);

  @factoryMethod
  static MainClass<SecondClasFromExtendedClass> createSecond(
          SecondClasFromExtendedClass extendedClass) =>
      MainClass(extendedClass);

  MainClass(this.extendedClass);
}

its generate error code

gh.factory<_i89.MainClass<dynamic>>(() =>
        _i89.MainClass<dynamic>.createFirst(
            gh<_i89.FirstClasFromExtendedClass>()));
image

and the correct one should be like this

gh.factory<_i89.MainClass<_i89.FirstClasFromExtendedClass>>(() =>
        _i89.MainClass.createFirst(
            gh<_i89.FirstClasFromExtendedClass>()));
    gh.factory<_i89.MainClass<_i89.SecondClasFromExtendedClass>>(() =>
        _i89.MainClass.createSecond(
            gh<_i89.SecondClasFromExtendedClass>()));

any suggestion or i do it wrong ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant