From e3ccd2b7f927628721015b8d720b06887b27fbff Mon Sep 17 00:00:00 2001 From: Andrew Scott Date: Thu, 27 May 2021 10:57:24 -0700 Subject: [PATCH] docs: clarify behavior of strict templates flags (#42392) fixes #39355 PR Close #42392 --- aio/content/guide/template-typecheck.md | 97 +++++++++++++------------ 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/aio/content/guide/template-typecheck.md b/aio/content/guide/template-typecheck.md index 095c3674e02ad..57dead83ede63 100644 --- a/aio/content/guide/template-typecheck.md +++ b/aio/content/guide/template-typecheck.md @@ -112,55 +112,56 @@ In case of a false positive like these, there are a few options: * You can disable certain type-checking operations individually, while maintaining strictness in other aspects, by setting a _strictness flag_ to `false`. * If you want to use `strictTemplates` and `strictNullChecks` together, you can opt out of strict null type checking specifically for input bindings via `strictNullInputTypes`. +Unless otherwise noted, each option below is set to the value for `strictTemplates` (`true` when `strictTemplates` is `true` and vice versa). - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Strictness flagEffect
`strictInputTypes`Whether the assignability of a binding expression to the `@Input()` field is checked. Also affects the inference of directive generic types.
`strictInputAccessModifiers`Whether access modifiers such as `private`/`protected`/`readonly` are honored when assigning a binding expression to an `@Input()`. If disabled, the access modifiers of the `@Input` are ignored; only the type is checked.
`strictNullInputTypes`Whether `strictNullChecks` is honored when checking `@Input()` bindings (per `strictInputTypes`). Turning this off can be useful when using a library that was not built with `strictNullChecks` in mind.
`strictAttributeTypes`Whether to check `@Input()` bindings that are made using text attributes (for example, `<mat-tab label="Step 1">` vs `<mat-tab [label]="'Step 1'">`).
`strictSafeNavigationTypes`Whether the return type of safe navigation operations (for example, `user?.name`) will be correctly inferred based on the type of `user`). If disabled, `user?.name` will be of type `any`.
`strictDomLocalRefTypes`Whether local references to DOM elements will have the correct type. If disabled `ref` will be of type `any` for `<input #ref>`.
`strictOutputEventTypes`Whether `$event` will have the correct type for event bindings to component/directive an `@Output()`, or to animation events. If disabled, it will be `any`.
`strictDomEventTypes`Whether `$event` will have the correct type for event bindings to DOM events. If disabled, it will be `any`.
`strictContextGenerics`Whether the type parameters of generic components will be inferred correctly (including any generic bounds). If disabled, any type parameters will be `any`.
`strictLiteralTypes`Whether object and array literals declared in the template will have their type inferred. If disabled, the type of such literals will be `any`.
Strictness flagEffect
strictInputTypesWhether the assignability of a binding expression to the @Input() field is checked. Also affects the inference of directive generic types.
strictInputAccessModifiersWhether access modifiers such as private/protected/readonly are honored when assigning a binding expression to an @Input(). If disabled, the access modifiers of the @Input are ignored; only the type is checked. This option is false by default, even with strictTemplates set to true.
strictNullInputTypesWhether strictNullChecks is honored when checking @Input() bindings (per strictInputTypes). Turning this off can be useful when using a library that was not built with strictNullChecks in mind.
strictAttributeTypesWhether to check @Input() bindings that are made using text attributes (for example, <mat-tab label="Step 1"> vs <mat-tab [label]="'Step 1'">).
strictSafeNavigationTypesWhether the return type of safe navigation operations (for example, user?.name) will be correctly inferred based on the type of user). If disabled, user?.name will be of type any.
strictDomLocalRefTypesWhether local references to DOM elements will have the correct type. If disabled ref will be of type any for <input #ref>.
strictOutputEventTypesWhether $event will have the correct type for event bindings to component/directive an @Output(), or to animation events. If disabled, it will be any.
strictDomEventTypesWhether $event will have the correct type for event bindings to DOM events. If disabled, it will be any.
strictContextGenericsWhether the type parameters of generic components will be inferred correctly (including any generic bounds). If disabled, any type parameters will be any.
strictLiteralTypesWhether object and array literals declared in the template will have their type inferred. If disabled, the type of such literals will be any. This flag is true when either fullTemplateTypeCheck or strictTemplates is set to true.
If you still have issues after troubleshooting with these flags, you can fall back to full mode by disabling `strictTemplates`.