chan4lk / blog

React + Github Issues 👉 Your Personal Blog 🔥

Home Page:https://chan4lk.github.io/blog/#/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Angular 9 strictTemplates Option

chan4lk opened this issue · comments

Enable Strict Templates

{
    "compilerOptions": {
      "experimentalDecorators": true,
                ...
    },
    "angularCompilerOptions": {
      "strictTemplates": true,
                ...
    }
}

When true, enables strict template type checking in Angular version 9. Strict mode is only available when using Ivy.

Additional strictness flags allow you to enable and disable specific types of strict template type checking. See troubleshooting template errors.

Disabling type checking using $any()

Disable checking of a binding expression by surrounding the expression in a call to the $any() cast pseudo-function. The compiler treats it as a cast to the any type just like in TypeScript when a or as any cast is used.

In the following example, casting person to the any type suppresses the error Property address does not exist.

@Component({
  selector: 'my-component',
  template: '{{$any(person).addresss.street}}'
})
class MyComponent {
  person?: Person;
}