Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit fc1a9a6

Browse files
Igonatowardbell
authored andcommitted
docs(dependency-injection): Clarify how TypeScript generates decorator metadata
closes #1960
1 parent ce8b947 commit fc1a9a6

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

public/docs/ts/latest/guide/dependency-injection.jade

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -430,11 +430,20 @@ block injectable-not-always-needed-in-ts
430430
+ifDocsFor('ts')
431431
.l-sub-section
432432
:marked
433-
Injectors use a class's constructor metadata to determine dependent types as
434-
identified by the constructor's parameter types.
435-
TypeScript generates such metadata for any class with a decorator, and any decorator will do.
436-
But of course, it is more meaningful to mark a class using the appropriate
437-
<a href="#{injMetaUrl}">InjectableMetadata</a> #{_decorator}.
433+
At runtime, injectors can read class metadata in the transpiled JavaScript code
434+
and use the constructor parameter type information
435+
to determine what things to inject.
436+
437+
Not every JavaScript class has metadata.
438+
The TypeScript compiler discards metadata by default.
439+
If the `emitDecoratorMetadata` compiler option is true
440+
(as it should be in the `tsconfig.json`),
441+
the compiler adds the metadata to the generated JavaScript
442+
for _every class with at least one decorator_.
443+
444+
While any decorator will trigger this effect, mark the service class with the
445+
<a href="#{injMetaUrl}">InjectableMetadata</a> #{_decorator}
446+
to make the intent clear.
438447

439448
.callout.is-critical
440449
header Always include the parentheses

0 commit comments

Comments
 (0)