February 2019
Beginner
694 pages
18h 4m
English
When an interface contains only optional properties, it is considered a weak type. In other words, if we create an object that implements a weak type interface, can we really say that the object implements the interface? Let's consider some code to find out, as follows:
interface IWeakType {
id?: number,
name?: string
}
let weakTypeNoOverlap: IWeakType;
weakTypeNoOverlap = { description: "my description" };
Here, we have defined an interface named IWeakType that contains two properties, named id and name. As both of these properties are optional, this interface is considered to be a weak type. We then define a variable named weakTypeNoOverlap, and specify this object to be of type IWeakType. On the last line of this code, we assign ...
Read now
Unlock full access