Table of Contents
Compiling a TypeScript ProgramMike walks through the structure of a TypeScript program, the TSC compiler CLI command, discusses how the compiler-emitted JS code changes depending on JS language level and module type, and demonstrates a program’s compiled output, including the type declaration file. A student's question regarding how to define multi-target output is also covered in this segment.
Variables & ValuesMike discusses simple let and const declarations, literal types, demonstrates TypeScript throwing a type error, implicit any, and adding type annotations. Defining function arguments and return values are also covered in this segment.
Typing FunctionsMike demonstrates the benefits of explicitly defining return types and discusses how to narrow down the location return type errors. A student's question regarding type and test driven development is also covered in this segment.
Optional PropertiesMike demonstrates how to state optional properties for objects using the ? operator and discusses the difference between optional properties and properties that have the option of being undefined. A demonstration of TypeScript throwing an excess property error, why the error exists, and how to handle the error is also provided in this segment.
Index Signatures & Object Q&AMike demonstrates how to represent a type for dictionaries to allow values of a consistent type to be retrievable by keys. Student questions regarding the excess property erroring case and why storing the object as a variable removes the error are also covered in this segment.
Structural vs Nominal TypesMike discusses type checking as the attempt to evaluate the question of compatibility or type equivalence and the meaning of duck typing. The difference between static and dynamic type systems, nominal and structural type systems, and strong and weak types are also described in this segment.
Union TypesMike briefly discusses both union and intersection types which can conceptually be thought of as logical boolean operators (AND, OR) as they pertain to types. Union types in TypeScript can be described using the | (pipe) operator. How to narrow with type guards and a description of discriminated unions is also covered in this segment.
Intersection TypesMike demonstrates intersection types in TypeScript which can be described using the & (ampersand) operator and walks through an example of adding extra data to a Date object. A student's question regarding clarification on the difference between union and intersection types is also covered in this segment.
Type AliasesMike provides a brief overview of the material covered Type Aliases and Interfaces segments, discusses what type aliases allow in TypeScript, and inheritance. Type aliases can define a more meaningful name for a type, declare the particulars of the type in a single place, and import and export this type from modules.
InterfacesMike discusses interfaces which can only be used to define object types and the formalities in regards to inheritance including extends and implements. Open interfaces, how to choose which to use between type aliases and interfaces, and recursive types are also covered in this segment.
JSON Types ExerciseMike walks through an exercise of defining correct types to describe given JSON values and suppress the thrown type check errors.
Functions & Function OverloadsMike discusses a brief overview of the functions section, the return type void, callable types, and construct signatures, which are interfaces or type aliases that describe something that can be invoked or instructed. Function overloads, where multiple function heads that serve as entry points to a single implementation are defined, are also demonstrated in this segment.
this Types & Best PracticesMike discusses how to handle and invoke a function that uses a this element, such as a click handler. A this type needs to be created in order for TypeScript to know which element this is talking about. Best practices for coding function types by explicitly defining return types is also covered in this segment.
Classes & Access Modifier KeywordsMike discusses how to define classes in TypeScript and access modifier keywords for limited exposure including public, private, and protected. JS private class fields, readonly, and param properties are also discussed in this segment.
Types & Values
Bottom Types: neverMike discusses bottom types which describe types that hold no possible value in the system with the key word never and walks through a use case for a bottom type in an exhaustive conditional. How to handle an exhaustive conditional with an unreachable error using an error subclass is also covered in this segment.
Type Guards & NarrowingMike discusses some of TypeScript's built-in type guards including typeof, instanceof, and property checks and demonstrates the types user-defined type guard. The two types of user-defined type guards covered in this segment include value is and asserts value is.
Nullish ValuesMike discusses nullish values including null, undefined, and void, the non-null assertion operator, and definite assignment operator. Although null, void, and undefined are all used to describe “nothing” or “empty”, they are independent types in TypeScript.
GenericsMike discusses generics which are a way of creating types that are expressed in terms of other types. A walk through of a potential use case, how to define a type parameter, and a demonstration of an example function running in TypeScript playground is also covered in this segment.
Dictionary map, filter & reduceMike provides and then live codes an exercise to practice using generics by building out some higher-order functions that can operate on dictionaries. The functions looked at in this segment are map, filter, and reduce.
Generics Scopes & RestraintsMike discusses where type parameters can be used depending on where they are defined and minimum requirements that can be imposed on type parameters. How to describe type constraints, the scope of generics, and best practices when defining a type parameter are also covered in this segment.