UNPKG

angular2

Version:

Angular 2 - a web framework for modern web apps

157 lines (155 loc) 5.06 kB
import { BaseException, WrappedException } from 'angular2/src/facade/exceptions'; import { ReflectiveKey } from './reflective_key'; import { ReflectiveInjector } from './reflective_injector'; /** * Base class for all errors arising from misconfigured providers. */ export declare class AbstractProviderError extends BaseException { constructor(injector: ReflectiveInjector, key: ReflectiveKey, constructResolvingMessage: Function); addKey(injector: ReflectiveInjector, key: ReflectiveKey): void; context: any; } /** * Thrown when trying to retrieve a dependency by `Key` from {@link Injector}, but the * {@link Injector} does not have a {@link Provider} for {@link Key}. * * ### Example ([live demo](http://plnkr.co/edit/vq8D3FRB9aGbnWJqtEPE?p=preview)) * * ```typescript * class A { * constructor(b:B) {} * } * * expect(() => Injector.resolveAndCreate([A])).toThrowError(); * ``` */ export declare class NoProviderError extends AbstractProviderError { constructor(injector: ReflectiveInjector, key: ReflectiveKey); } /** * Thrown when dependencies form a cycle. * * ### Example ([live demo](http://plnkr.co/edit/wYQdNos0Tzql3ei1EV9j?p=info)) * * ```typescript * var injector = Injector.resolveAndCreate([ * provide("one", {useFactory: (two) => "two", deps: [[new Inject("two")]]}), * provide("two", {useFactory: (one) => "one", deps: [[new Inject("one")]]}) * ]); * * expect(() => injector.get("one")).toThrowError(); * ``` * * Retrieving `A` or `B` throws a `CyclicDependencyError` as the graph above cannot be constructed. */ export declare class CyclicDependencyError extends AbstractProviderError { constructor(injector: ReflectiveInjector, key: ReflectiveKey); } /** * Thrown when a constructing type returns with an Error. * * The `InstantiationError` class contains the original error plus the dependency graph which caused * this object to be instantiated. * * ### Example ([live demo](http://plnkr.co/edit/7aWYdcqTQsP0eNqEdUAf?p=preview)) * * ```typescript * class A { * constructor() { * throw new Error('message'); * } * } * * var injector = Injector.resolveAndCreate([A]); * try { * injector.get(A); * } catch (e) { * expect(e instanceof InstantiationError).toBe(true); * expect(e.originalException.message).toEqual("message"); * expect(e.originalStack).toBeDefined(); * } * ``` */ export declare class InstantiationError extends WrappedException { constructor(injector: ReflectiveInjector, originalException: any, originalStack: any, key: ReflectiveKey); addKey(injector: ReflectiveInjector, key: ReflectiveKey): void; wrapperMessage: string; causeKey: ReflectiveKey; context: any; } /** * Thrown when an object other then {@link Provider} (or `Type`) is passed to {@link Injector} * creation. * * ### Example ([live demo](http://plnkr.co/edit/YatCFbPAMCL0JSSQ4mvH?p=preview)) * * ```typescript * expect(() => Injector.resolveAndCreate(["not a type"])).toThrowError(); * ``` */ export declare class InvalidProviderError extends BaseException { constructor(provider: any); } /** * Thrown when the class has no annotation information. * * Lack of annotation information prevents the {@link Injector} from determining which dependencies * need to be injected into the constructor. * * ### Example ([live demo](http://plnkr.co/edit/rHnZtlNS7vJOPQ6pcVkm?p=preview)) * * ```typescript * class A { * constructor(b) {} * } * * expect(() => Injector.resolveAndCreate([A])).toThrowError(); * ``` * * This error is also thrown when the class not marked with {@link Injectable} has parameter types. * * ```typescript * class B {} * * class A { * constructor(b:B) {} // no information about the parameter types of A is available at runtime. * } * * expect(() => Injector.resolveAndCreate([A,B])).toThrowError(); * ``` */ export declare class NoAnnotationError extends BaseException { constructor(typeOrFunc: any, params: any[][]); private static _genMessage(typeOrFunc, params); } /** * Thrown when getting an object by index. * * ### Example ([live demo](http://plnkr.co/edit/bRs0SX2OTQiJzqvjgl8P?p=preview)) * * ```typescript * class A {} * * var injector = Injector.resolveAndCreate([A]); * * expect(() => injector.getAt(100)).toThrowError(); * ``` */ export declare class OutOfBoundsError extends BaseException { constructor(index: any); } /** * Thrown when a multi provider and a regular provider are bound to the same token. * * ### Example * * ```typescript * expect(() => Injector.resolveAndCreate([ * new Provider("Strings", {useValue: "string1", multi: true}), * new Provider("Strings", {useValue: "string2", multi: false}) * ])).toThrowError(); * ``` */ export declare class MixingMultiProvidersWithRegularProvidersError extends BaseException { constructor(provider1: any, provider2: any); }