UNPKG

5.91 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 */
8/**
9 * Type of the Inject decorator / constructor function.
10 *
11 * @stable
12 */
13export interface InjectDecorator {
14 /**
15 * @whatItDoes A parameter decorator that specifies a dependency.
16 * @howToUse
17 * ```
18 * @Injectable()
19 * class Car {
20 * constructor(@Inject("MyEngine") public engine:Engine) {}
21 * }
22 * ```
23 *
24 * @description
25 * For more details, see the {@linkDocs guide/dependency-injection "Dependency Injection Guide"}.
26 *
27 * ### Example
28 *
29 * {@example core/di/ts/metadata_spec.ts region='Inject'}
30 *
31 * When `@Inject()` is not present, {@link Injector} will use the type annotation of the
32 * parameter.
33 *
34 * ### Example
35 *
36 * {@example core/di/ts/metadata_spec.ts region='InjectWithoutDecorator'}
37 *
38 * @stable
39 */
40 (token: any): any;
41 new (token: any): Inject;
42}
43/**
44 * Type of the Inject metadata.
45 *
46 * @stable
47 */
48export interface Inject {
49 token: any;
50}
51/**
52 * Inject decorator and metadata.
53 *
54 * @stable
55 * @Annotation
56 */
57export declare const Inject: InjectDecorator;
58/**
59 * Type of the Optional decorator / constructor function.
60 *
61 * @stable
62 */
63export interface OptionalDecorator {
64 /**
65 * @whatItDoes A parameter metadata that marks a dependency as optional.
66 * {@link Injector} provides `null` if the dependency is not found.
67 * @howToUse
68 * ```
69 * @Injectable()
70 * class Car {
71 * constructor(@Optional() public engine:Engine) {}
72 * }
73 * ```
74 *
75 * @description
76 * For more details, see the {@linkDocs guide/dependency-injection "Dependency Injection Guide"}.
77 *
78 * ### Example
79 *
80 * {@example core/di/ts/metadata_spec.ts region='Optional'}
81 *
82 * @stable
83 */
84 (): any;
85 new (): Optional;
86}
87/**
88 * Type of the Optional metadata.
89 *
90 * @stable
91 */
92export interface Optional {
93}
94/**
95 * Optional decorator and metadata.
96 *
97 * @stable
98 * @Annotation
99 */
100export declare const Optional: OptionalDecorator;
101/**
102 * Type of the Injectable decorator / constructor function.
103 *
104 * @stable
105 */
106export interface InjectableDecorator {
107 /**
108 * @whatItDoes A marker metadata that marks a class as available to {@link Injector} for creation.
109 * @howToUse
110 * ```
111 * @Injectable()
112 * class Car {}
113 * ```
114 *
115 * @description
116 * For more details, see the {@linkDocs guide/dependency-injection "Dependency Injection Guide"}.
117 *
118 * ### Example
119 *
120 * {@example core/di/ts/metadata_spec.ts region='Injectable'}
121 *
122 * {@link Injector} will throw {@link NoAnnotationError} when trying to instantiate a class that
123 * does not have `@Injectable` marker, as shown in the example below.
124 *
125 * {@example core/di/ts/metadata_spec.ts region='InjectableThrows'}
126 *
127 * @stable
128 */
129 (): any;
130 new (): Injectable;
131}
132/**
133 * Type of the Injectable metadata.
134 *
135 * @stable
136 */
137export interface Injectable {
138}
139/**
140 * Injectable decorator and metadata.
141 *
142 * @stable
143 * @Annotation
144 */
145export declare const Injectable: InjectableDecorator;
146/**
147 * Type of the Self decorator / constructor function.
148 *
149 * @stable
150 */
151export interface SelfDecorator {
152 /**
153 * @whatItDoes Specifies that an {@link Injector} should retrieve a dependency only from itself.
154 * @howToUse
155 * ```
156 * @Injectable()
157 * class Car {
158 * constructor(@Self() public engine:Engine) {}
159 * }
160 * ```
161 *
162 * @description
163 * For more details, see the {@linkDocs guide/dependency-injection "Dependency Injection Guide"}.
164 *
165 * ### Example
166 *
167 * {@example core/di/ts/metadata_spec.ts region='Self'}
168 *
169 * @stable
170 */
171 (): any;
172 new (): Self;
173}
174/**
175 * Type of the Self metadata.
176 *
177 * @stable
178 */
179export interface Self {
180}
181/**
182 * Self decorator and metadata.
183 *
184 * @stable
185 * @Annotation
186 */
187export declare const Self: SelfDecorator;
188/**
189 * Type of the SkipSelf decorator / constructor function.
190 *
191 * @stable
192 */
193export interface SkipSelfDecorator {
194 /**
195 * @whatItDoes Specifies that the dependency resolution should start from the parent injector.
196 * @howToUse
197 * ```
198 * @Injectable()
199 * class Car {
200 * constructor(@SkipSelf() public engine:Engine) {}
201 * }
202 * ```
203 *
204 * @description
205 * For more details, see the {@linkDocs guide/dependency-injection "Dependency Injection Guide"}.
206 *
207 * ### Example
208 *
209 * {@example core/di/ts/metadata_spec.ts region='SkipSelf'}
210 *
211 * @stable
212 */
213 (): any;
214 new (): SkipSelf;
215}
216/**
217 * Type of the SkipSelf metadata.
218 *
219 * @stable
220 */
221export interface SkipSelf {
222}
223/**
224 * SkipSelf decorator and metadata.
225 *
226 * @stable
227 * @Annotation
228 */
229export declare const SkipSelf: SkipSelfDecorator;
230/**
231 * Type of the Host decorator / constructor function.
232 *
233 * @stable
234 */
235export interface HostDecorator {
236 /**
237 * @whatItDoes Specifies that an injector should retrieve a dependency from any injector until
238 * reaching the host element of the current component.
239 * @howToUse
240 * ```
241 * @Injectable()
242 * class Car {
243 * constructor(@Host() public engine:Engine) {}
244 * }
245 * ```
246 *
247 * @description
248 * For more details, see the {@linkDocs guide/dependency-injection "Dependency Injection Guide"}.
249 *
250 * ### Example
251 *
252 * {@example core/di/ts/metadata_spec.ts region='Host'}
253 *
254 * @stable
255 */
256 (): any;
257 new (): Host;
258}
259/**
260 * Type of the Host metadata.
261 *
262 * @stable
263 */
264export interface Host {
265}
266/**
267 * Host decorator and metadata.
268 *
269 * @stable
270 * @Annotation
271 */
272export declare const Host: HostDecorator;