docs(dependency-injection): Clarify how TypeScript generates decorator metadata

closes #1960
This commit is contained in:
Ignat Shining 2016-07-25 00:29:11 +03:00 committed by Ward Bell
parent ce8b94799c
commit fc1a9a6026
1 changed files with 14 additions and 5 deletions

View File

@ -430,11 +430,20 @@ block injectable-not-always-needed-in-ts
+ifDocsFor('ts') +ifDocsFor('ts')
.l-sub-section .l-sub-section
:marked :marked
Injectors use a class's constructor metadata to determine dependent types as At runtime, injectors can read class metadata in the transpiled JavaScript code
identified by the constructor's parameter types. and use the constructor parameter type information
TypeScript generates such metadata for any class with a decorator, and any decorator will do. to determine what things to inject.
But of course, it is more meaningful to mark a class using the appropriate
<a href="#{injMetaUrl}">InjectableMetadata</a> #{_decorator}. Not every JavaScript class has metadata.
The TypeScript compiler discards metadata by default.
If the `emitDecoratorMetadata` compiler option is true
(as it should be in the `tsconfig.json`),
the compiler adds the metadata to the generated JavaScript
for _every class with at least one decorator_.
While any decorator will trigger this effect, mark the service class with the
<a href="#{injMetaUrl}">InjectableMetadata</a> #{_decorator}
to make the intent clear.
.callout.is-critical .callout.is-critical
header Always include the parentheses header Always include the parentheses