function flushTypeQueue() {
    while(typeQueue.length) {
      var type = typeQueue.shift();
      if (type.pattern) throw new Error("You cannot override a type's .pattern at runtime.");
      angular.extend($types[type.name], injector.invoke(type.def));
    }
  }
@ngdoc function
@name ui.router.util.$urlMatcherFactory#type
@methodOf ui.router.util.$urlMatcherFactory

@description
Registers a custom {@link ui.router.util.type:Type `Type`} object that can be used to
generate URLs with typed parameters.

@param {string} name  The type name.
@param {Object|Function} definition   The type definition. See
       {@link ui.router.util.type:Type `Type`} for information on the values accepted.
@param {Object|Function} definitionFn (optional) A function that is injected before the app
       runtime starts.  The result of this function is merged into the existing `definition`.
       See {@link ui.router.util.type:Type `Type`} for information on the values accepted.

@returns {Object}  Returns `$urlMatcherFactoryProvider`.

@example
This is a simple example of a custom type that encodes and decodes items from an
array, using the array index as the URL-encoded value:

<pre>
var list = ['John', 'Paul', 'George', 'Ringo'];

$urlMatcherFactoryProvider.type('listItem', {
  encode: function(item) {
    // Represent the list item in the URL using its corresponding index
    return list.indexOf(item);
  },
  decode: function(item) {
    // Look up the list item by index
    return list[parseInt(item, 10)];
  },
  is: function(item) {
    // Ensure the item is valid by checking to see that it appears
    // in the list
    return list.indexOf(item) > -1;
  }
});

$stateProvider.state('list', {
  url: "/list/{item:listItem}",
  controller: function($scope, $stateParams) {
    console.log($stateParams.item);
  }
});

// ...

// Changes URL to '/list/3', logs "Ringo" to the console
$state.go('list', { item: "Ringo" });
</pre>

This is a more complex example of a type that relies on dependency injection to
interact with services, and uses the parameter name from the URL to infer how to
handle encoding and decoding parameter values:

<pre>
// Defines a custom type that gets a value from a service,
// where each service gets different types of values from
// a backend API:
$urlMatcherFactoryProvider.type('dbObject', {}, function(Users, Posts) {

  // Matches up services to URL parameter names
  var services = {
    user: Users,
    post: Posts
  };

  return {
    encode: function(object) {
      // Represent the object in the URL using its unique ID
      return object.id;
    },
    decode: function(value, key) {
      // Look up the object by ID, using the parameter
      // name (key) to call the correct service
      return services[key].findById(value);
    },
    is: function(object, key) {
      // Check that object is a valid dbObject
      return angular.isObject(object) && object.id && services[key];
    }
    equals: function(a, b) {
      // Check the equality of decoded objects by comparing
      // their unique IDs
      return a.id === b.id;
    }
  };
});

// In a config() block, you can then attach URLs with
// type-annotated parameters:
$stateProvider.state('users', {
  url: "/users",
  // ...
}).state('users.item', {
  url: "/{user:dbObject}",
  controller: function($scope, $stateParams) {
    // $stateParams.user will now be an object returned from
    // the Users service
  },
  // ...
});
</pre>