Skip to content

Type argument 'T' doesn't conform to the bound 'Object' of the type variable 'T' on 'GetIt.get' #187

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

Closed
srnunio opened this issue May 6, 2021 · 2 comments

Comments

@srnunio
Copy link

srnunio commented May 6, 2021

My code breaks when I change:

environment:
  sdk: ">=2.7.0-0 <3.0.0"

to

environment:
  sdk: ">=2.12.0-0 <3.0.0"

I migrated my project to null safety and now I have this error when trying to run

Type argument 'T' doesn't conform to the bound 'Object' of the type variable 'T' on 'GetIt.get'.
     - 'Object' is from 'dart:core'.
     - 'GetIt' is from 'package:get_it/get_it.dart'
import 'package:get_it/get_it.dart';

final _injector = GetIt.instance;

T inject<T>() => _injector.get<T>(); // This is the line causing the error

I'm using the latest version 7.1.2

@escamoteur
Copy link
Collaborator

GetIt now enforces that T has to be minimal of type Object. So you have to

change your line to:

T inject<T extends Object>() => _injector.get<T>();

@srnunio
Copy link
Author

srnunio commented May 6, 2021

GetIt now enforces that T has to be minimal of type Object. So you have to

change your line to:

T inject<T extends Object>() => _injector.get<T>();

Thank you very much, this worked for me. 🥳

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

2 participants