1.

How to enforce strict null checks in TypeScript?

Answer»

Null pointers are ONE of the most common sources of unexpected runtime errors in programming. TYPESCRIPT HELPS you avoid them to a large degree by enforcing strict null checks.

You can enforce strict null checks in two ways:

  • providing the --strictNullChecks flag to the TypeScript (tsc) compiler
  • setting the strictNullChecks property to true in the tsconfig.json CONFIGURATION file.

When the flag is false, TypeScript IGNORES null and undefined values in the code. When it is true, null and undefined have their distinct types. The compiler throws a type error if you try to use them where a concrete value is expected.



Discussion

No Comment Found