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