Course Overview
Master TypeScript, the powerful superset of JavaScript that enables static typing and modern development workflows. This short but comprehensive course covers everything from foundational concepts to advanced features, including utility types, generics, type narrowing, and modern tooling. Learn to write safer, scalable, and maintainable code with TypeScript, with a focus on functional programming and clean code practices.
Perfect for developers aiming to build applications with frameworks like Angular, React, and other modern libraries.
What you will learn:
- Set up and configure TypeScript projects with modern tools like Vite and Babel.
- Understand type annotations, advanced types, and the type system.
- Explore interfaces and type aliases to design flexible and reusable types.
- Master functions with overloads, generics, async/await, and typed callbacks.
- Work with classes, including access modifiers, inheritance, generics, and decorators.
- Use utility types (
Partial
,Pick
,Omit
, etc.) and extend them with libraries likets-essentials
. - Apply type operators (
typeof
,keyof
,in
,as
) and advanced type narrowing. - Leverage modern features like template literal types and conditional types.
- Write clean, maintainable code with a functional programming style.
- Build real-world solutions with TypeScript for frameworks like Angular, React, and beyond.
Course Prerequisites
This course is geared towards developers needing to get up to speed with TypeScript quickly. Developers should be familiar with JavaScript. We recommend students following the Introduction to Modern JavaScript course prior to this one.
Outline
Introduction
- Introduce TypeScript: its purpose, benefits
- Understand TypeScript's relationship with JavaScript.
- Set up a TypeScript project using modern tools (e.g., Vite, Babel, or
tsc
). - Configure the TypeScript compiler with
tsconfig.json
. - Use ESLint for TypeScript.
- Integrate TypeScript with Babel for transpilation.
- Explore toolchains and bundlers (e.g., Vite, Webpack, Rollup).
- Configure module resolution strategies in
tsconfig.json
. - Use path aliases in
tsconfig.json
for cleaner and shorter imports.
Type Annotations Introduction
- Understand the type system and its role in catching errors early.
- Handle null and undefined safely using
strictNullChecks
and optional chaining (?.
). - Avoid using
any
and prefer stricter types to maintain type safety. - Use type aliases for defining custom, reusable types.
- Write and use enums for named constants.
- Work with arrays and their type annotations.
- Use tuples to define fixed-length, ordered arrays.
- Explore advanced types such as unions and intersections.
- Understand and use the unknown type as a safer alternative to
any
.
Functions
- Define and use functions with type annotations.
- Work with function parameters: optional parameters, default values, and rest parameters.
- Explore function overloads to handle multiple call signatures.
- Use type guards (e.g.,
typeof
,instanceof
, and custom type predicates). - Leverage type queries to infer types dynamically.
- Understand arrow functions and their use in TypeScript.
- Define return type annotations to explicitly specify function outputs.
- Create function types for variables and callbacks using type annotations and type aliases.
- Explore the satisfies operator for precise type inference.
- Use callback functions with properly typed parameters and return values.
- Handle this context in functions with type annotations.
- Define and use generic functions for reusable and type-safe logic.
- Use utility types like
Parameters<T>
,ReturnType<T>
, andConstructorParameters<T>
. - Use async/await for asynchronous functions with proper typing of
Promise
results.
Interfaces and Type Definitions
- Define interfaces to describe object shapes.
- Use type aliases to define custom types (including primitives, unions, and intersections).
- Compare interfaces and type aliases and understand when to use each.
- Use duck typing with interfaces to enforce structural typing.
- Define properties, including optional and readonly properties.
- Create indexable types for dynamic property names.
- Define function types and constructor types with interfaces and type aliases.
- Use union and intersection types to combine and extend definitions.
- Extend interfaces and type aliases with inheritance and composition.
- Use the
Record<K, T>
utility type for mapping keys to specific types. - Explore
keyof
to extract keys from a type or interface. - Combine
keyof
andRecord
for advanced key-based typing. - Understand the limitations of interfaces compared to type aliases (e.g., unions, primitives).
Classes
- Write classes and understand their role in TypeScript.
- Define properties and methods in a class.
- Use access modifiers (
public
,private
,protected
) to control member visibility. - Understand scopes and the
this
keyword in class methods. - Use parameter properties to simplify constructor initialization.
- Implement inheritance for reusing and extending class behavior.
- Override methods using the
override
keyword for clarity and safety. - Create and use abstract classes and abstract methods.
- Write getters and setters (accessors) for controlled property access.
- Define and use static members for class-level properties and methods.
- Understand and use the readonly modifier for immutable class properties.
- Explore interfaces to define contracts for classes.
- Combine classes with type aliases for advanced flexibility.
- Implement generics in classes for reusable, type-safe logic.
- Use decorators to extend and annotate class behavior.
Utility Types
- Use built-in utility types:
Partial
,Required
,Readonly
,Pick
,Omit
,Record
,Exclude
,Extract
, andNonNullable
.
- Combine
keyof
and utility types for dynamic type manipulation. - Work with mapped types for advanced type transformations.
- Extend utility types with libraries like
ts-essentials
:DeepRequired
,DeepPartial
,DeepReadonly
,Exact
, etc.
- Combine utility types for complex and flexible type definitions.
- Explore real-world use cases for utility types.