In this section, we are going to learn about some of the core features of the TypeScript type system. This includes concepts such as union types, intersection guards, type guards, and type aliases.
Core features of the TypeScript type system
Union types
TypeScript allows you to declare union types:
let path: string[]|string;
path = "/temp/log.xml";
path = ["/temp/log.xml", "/temp/errors.xml"];
path = 1; // Error
In the preceding example, we have declared a variable named path that can contain a single path (string) or a collection of paths (array of strings). In the example, we have also set the value of the variable. We assigned a string and an array of strings without errors; however, when we attempted...