provideType<T extends Object> method

T provideType<T extends Object>(
  1. Type token

Finds and returns an object instance provided for a type token.

A runtime assertion is thrown in debug mode if:

  • T is explicitly or implicitly bound to dynamic.
  • If T is not Object, the DI token is not the same as T.

An error is thrown if a provider is not found.


T provideType<T extends Object>(Type token) {
  // NOTE: It is not possible to design this API in such a way that only "T"
  // can be used, and not require "token" as well. Our injection system
  // currently uses "identical" (similar to JS' ===), and the types passed
  // through "T" are not canonical (they are == equivalent, but not ===).
  // See historic discussion here:
  assert(T != dynamic, 'Returning a dynamic is not supported');
  return unsafeCast(get(token));