UNPKG

4.6 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright Google Inc. All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8import { Type } from './facade/type';
9import { ReflectiveInjector } from './reflective_injector';
10import { ReflectiveKey } from './reflective_key';
11export interface InjectionError extends Error {
12 keys: ReflectiveKey[];
13 injectors: ReflectiveInjector[];
14 constructResolvingMessage: (this: InjectionError) => string;
15 addKey(injector: ReflectiveInjector, key: ReflectiveKey): void;
16}
17/**
18 * Thrown when trying to retrieve a dependency by key from {@link Injector}, but the
19 * {@link Injector} does not have a {@link Provider} for the given key.
20 *
21 * ### Example ([live demo](http://plnkr.co/edit/vq8D3FRB9aGbnWJqtEPE?p=preview))
22 *
23 * ```typescript
24 * class A {
25 * constructor(b:B) {}
26 * }
27 *
28 * expect(() => Injector.resolveAndCreate([A])).toThrowError();
29 * ```
30 */
31export declare function noProviderError(injector: ReflectiveInjector, key: ReflectiveKey): InjectionError;
32/**
33 * Thrown when dependencies form a cycle.
34 *
35 * ### Example ([live demo](http://plnkr.co/edit/wYQdNos0Tzql3ei1EV9j?p=info))
36 *
37 * ```typescript
38 * var injector = Injector.resolveAndCreate([
39 * {provide: "one", useFactory: (two) => "two", deps: [[new Inject("two")]]},
40 * {provide: "two", useFactory: (one) => "one", deps: [[new Inject("one")]]}
41 * ]);
42 *
43 * expect(() => injector.get("one")).toThrowError();
44 * ```
45 *
46 * Retrieving `A` or `B` throws a `CyclicDependencyError` as the graph above cannot be constructed.
47 */
48export declare function cyclicDependencyError(injector: ReflectiveInjector, key: ReflectiveKey): InjectionError;
49/**
50 * Thrown when a constructing type returns with an Error.
51 *
52 * The `InstantiationError` class contains the original error plus the dependency graph which caused
53 * this object to be instantiated.
54 *
55 * ### Example ([live demo](http://plnkr.co/edit/7aWYdcqTQsP0eNqEdUAf?p=preview))
56 *
57 * ```typescript
58 * class A {
59 * constructor() {
60 * throw new Error('message');
61 * }
62 * }
63 *
64 * var injector = Injector.resolveAndCreate([A]);
65
66 * try {
67 * injector.get(A);
68 * } catch (e) {
69 * expect(e instanceof InstantiationError).toBe(true);
70 * expect(e.originalException.message).toEqual("message");
71 * expect(e.originalStack).toBeDefined();
72 * }
73 * ```
74 */
75export declare function instantiationError(injector: ReflectiveInjector, originalException: any, originalStack: any, key: ReflectiveKey): InjectionError;
76/**
77 * Thrown when an object other then {@link Provider} (or `Type`) is passed to {@link Injector}
78 * creation.
79 *
80 * ### Example ([live demo](http://plnkr.co/edit/YatCFbPAMCL0JSSQ4mvH?p=preview))
81 *
82 * ```typescript
83 * expect(() => Injector.resolveAndCreate(["not a type"])).toThrowError();
84 * ```
85 */
86export declare function invalidProviderError(provider: any): Error;
87/**
88 * Thrown when the class has no annotation information.
89 *
90 * Lack of annotation information prevents the {@link Injector} from determining which dependencies
91 * need to be injected into the constructor.
92 *
93 * ### Example ([live demo](http://plnkr.co/edit/rHnZtlNS7vJOPQ6pcVkm?p=preview))
94 *
95 * ```typescript
96 * class A {
97 * constructor(b) {}
98 * }
99 *
100 * expect(() => Injector.resolveAndCreate([A])).toThrowError();
101 * ```
102 *
103 * This error is also thrown when the class not marked with {@link Injectable} has parameter types.
104 *
105 * ```typescript
106 * class B {}
107 *
108 * class A {
109 * constructor(b:B) {} // no information about the parameter types of A is available at runtime.
110 * }
111 *
112 * expect(() => Injector.resolveAndCreate([A,B])).toThrowError();
113 * ```
114 * @stable
115 */
116export declare function noAnnotationError(typeOrFunc: Type<any> | Function, params: any[][]): Error;
117/**
118 * Thrown when getting an object by index.
119 *
120 * ### Example ([live demo](http://plnkr.co/edit/bRs0SX2OTQiJzqvjgl8P?p=preview))
121 *
122 * ```typescript
123 * class A {}
124 *
125 * var injector = Injector.resolveAndCreate([A]);
126 *
127 * expect(() => injector.getAt(100)).toThrowError();
128 * ```
129 * @stable
130 */
131export declare function outOfBoundsError(index: number): Error;
132/**
133 * Thrown when a multi provider and a regular provider are bound to the same token.
134 *
135 * ### Example
136 *
137 * ```typescript
138 * expect(() => Injector.resolveAndCreate([
139 * { provide: "Strings", useValue: "string1", multi: true},
140 * { provide: "Strings", useValue: "string2", multi: false}
141 * ])).toThrowError();
142 * ```
143 */
144export declare function mixingMultiProvidersWithRegularProvidersError(provider1: any, provider2: any): Error;