February 2019
Beginner
694 pages
18h 4m
English
Similar to the strictNullChecks compile option, we can also check whether the properties of a class have been initialized correctly using the strictPropertyInitialization compiler flag. Consider the following class definition:
class WithoutInit {
a: number;
b: string;
}
Here, we have a standard class definition for a class named WithoutInit. This class has two properties, named a, of type number, and b, of type string. With the strictPropertyInitialization compile option turned on, this code will generate the following errors:
error TS2564: Property 'a' has no initializer and is not definitely assigned in the constructor. error TS2564: Property 'b' has no initializer and is not definitely assigned in the constructor. ...
Read now
Unlock full access