Thursday 5 August 2021

Angular in Strict Mode

So I wanted to use the new "strict" settings when compiling my Angular apps.

This is a small blog on the issues I ran into.

Luckily, similar issues can be found when you move over to Kotlin from Java.

I've posted links in the References below of blog posts that delve deeper into the strict setting.

Solutions

  1. initialize variables
  2. add | undefined or | null and add if-then checks everywhere
  3. use ?. syntax (mostly in templates)

Problems

Check everything, because suddenly we have values everywhere (perhaps due to point 1 above) and checks for existing values now always turn true.

Where a null value was previously sent appropriately to the rest service, suddenly it has an initial value of '', and now the parsing of the JSON fails.

References

InDepthDev - Bulletproof Angular. Angular strict mode explained
https://indepth.dev/posts/1402/bulletproof-angular
THE ART OF SIMPLICITY - Angular 10–Strict mode
https://bartwullems.blogspot.com/2020/09/angular-10strict-mode.html
Guide for Type-safe Angular
https://medium.com/lacolaco-blog/guide-for-type-safe-angular-6e9562499d93
MW Experts - Strict rules for new Angular project
https://medium.com/most-wanted-experts/strict-rules-for-new-angular-project-7cbd32f37163