February 2019
Beginner
694 pages
18h 4m
English
TypeScript also uses a method called duck typing for more complex variable types. Duck typing suggests that if it looks like a duck, and walks like a duck, then it probably is a duck. In other words, two variables are considered equal if they have the same properties and methods, as they can be exchanged for one another, but will still provide the same behavior. Consider the following TypeScript code:
var complexType = { name: "myName", id: 1 };
complexType = { id: 2, name: "anotherName" };
We start with a variable named complexType that has been assigned a simple JavaScript object with a name and id property. On our second line of code, we are reassigning the value of this complexType variable to another object that also has ...
Read now
Unlock full access