Search⌘ K

Strict Property Initialization

Explore how enabling strictPropertyInitialization in TypeScript requires all class properties to be properly initialized to avoid undefined values. Understand three strategies to fix initialization errors and the relation to strictNullChecks. This lesson helps you write safer and more reliable TypeScript classes by preventing type mismatches caused by uninitialized properties.

Definition

The flag we’re talking about is called strictPropertyInitialization. As usual, let’s look at the definition from the documentation. I think it’s rather self-explanatory.

Ensure non-undefined class properties are initialized in the constructor. This option requires – strictNullChecks be ...