typescript-book README

The project's README from github.com/gibbok/typescript-book. As one markdown file: README.md.

The Concise TypeScript Book

The Concise TypeScript Book provides a comprehensive and succinct overview of TypeScript's capabilities. It offers clear explanations covering all aspects of the latest version of the language, from its powerful type system to advanced features.

Whether you're a beginner or an experienced developer, this book is an invaluable resource to enhance your understanding and proficiency in TypeScript.

This book is completely free and open source.

I believe that high-quality technical education should be accessible to everyone. For this reason, I keep the book freely available and regularly update it with improvements, and new examples.

Discover The Concise TypeScript Book Plus Edition.

The Concise TypeScript Book Plus Edition cover

For readers who want to go beyond the open-source edition, The Concise TypeScript Book Plus Edition: React and Real-World Patterns for TypeScript 7 includes additional and exclusive content focused on practical application.

The Plus Edition includes:

By purchasing the Plus Edition, you also directly support the continued development and maintenance of the free and open-source book.

The Plus Edition is available in English and Italian on Amazon worldwide. Explore the Plus Edition and buy on Amazon.

Support the Project

If the free book helped you fix a bug, understand a difficult concept, or advance in your career, please consider supporting my work by paying what you want, with a suggested contribution of $5, or by sponsoring a coffee.

Your support helps me keep the content up to date and expand it with new examples, clearer explanations, and additional practical guidance.

Buy Me a Coffee

Donate

Translations

This book has been translated into several languages, including:

English

Bulgarian

German

French

Indonesian

Italian

Japanese

Korean

Polish

Portuguese (Brazil)

Swedish

Turkish

Vietnamese

Chinese

Spanish

Thai

Russian

Arabic

Downloads and website

You can also download the EPUB version:

https://github.com/gibbok/typescript-book/tree/main/downloads

An online version is available at:

https://gibbok.github.io/typescript-book

Table of Contents

Introduction

Welcome to The Concise TypeScript Book! This guide equips you with essential knowledge and practical skills for effective TypeScript development. Discover key concepts and techniques to write clean, robust code. Whether you're a beginner or an experienced developer, this book serves as both a comprehensive guide and a handy reference for leveraging TypeScript's power in your projects.

This book covers TypeScript 7.0.

About the Author

Simone Poggiali is an experienced Staff Engineer with a passion for writing professional-grade code since the 90s. Throughout his international career, he has contributed to numerous projects for a wide range of clients, from startups to large organizations. Notable companies such as HelloFresh, Siemens, O2, Leroy Merlin and Snowplow have benefited from his expertise and dedication.

You can reach Simone Poggiali on the following platforms:

Full list of contributors: https://github.com/gibbok/typescript-book/graphs/contributors

TypeScript Introduction

What is TypeScript?

TypeScript is a strongly typed programming language that builds on JavaScript. It was originally designed by Anders Hejlsberg in 2012 and is currently developed and maintained by Microsoft as an open source project.

TypeScript compiles to JavaScript and can be executed in any JavaScript runtime (e.g., a browser or Node.js on a server).

It supports multiple programming paradigms such as functional, generic, imperative, and object-oriented programming, and is a compiled (transpiled) language that is converted into JavaScript before execution.

Why TypeScript?

TypeScript is a strongly typed language that helps prevent common programming mistakes and avoid certain kinds of run-time errors before the program is executed.

A strongly typed language allows the developer to specify various program constraints and behaviors in the data type definitions, facilitating the ability to verify the correctness of the software and prevent defects. This is especially valuable in large-scale applications.

Some of the benefits of TypeScript:

TypeScript and JavaScript

TypeScript is written in .ts or .tsx files, while JavaScript files are written in .js or .jsx.

Files with the extension .tsx or .jsx can contain JavaScript Syntax Extension JSX, which is used in React for UI development.

TypeScript is a typed superset of JavaScript (ECMAScript 2015) in terms of syntax. All JavaScript code is valid TypeScript code, but the reverse is not always true.

For instance, consider a function in a JavaScript file with the .js extension, such as the following:

const sum = (a, b) => a + b;

The function can be converted and used in TypeScript by changing the file extension to .ts. However, if the same function is annotated with TypeScript types, it cannot be executed in any JavaScript runtime without compilation. The following TypeScript code will produce a syntax error if it is not compiled:

const sum = (a: number, b: number): number => a + b;

TypeScript was designed to detect potential runtime errors at compile time by allowing developers to express intent through type annotations. In addition, TypeScript can also catch certain issues even when no explicit type annotations are provided, thanks to type inference. For example, the following code snippet does not specify any TypeScript types:

const items = [{ x: 1 }, { x: 2 }];
const result = items.filter(item => item.y);

In this case, TypeScript detects an error and reports:

Property 'y' does not exist on type '{ x: number; }'.

TypeScript's type system is largely influenced by the runtime behavior of JavaScript. For example, the addition operator (+), which in JavaScript can either perform string concatenation or numeric addition, is modeled in the same way in TypeScript:

const result = '1' + 1; // Result is of type string

The team behind TypeScript has made a deliberate decision to flag unusual usage of JavaScript as errors. For instance, consider the following valid JavaScript code:

const result = 1 + true; // In JavaScript, the result is equal to 2

However, TypeScript throws an error:

Operator '+' cannot be applied to types 'number' and 'boolean'.

This error occurs because TypeScript strictly enforces type compatibility, and in this case, it identifies an invalid ope

typescript-book (gibbok/typescript-book)

Searching Database…

What is this?The Concise TypeScript Book: a free, open-source book giving a succinct overview of TypeScript, from its powerful type system to advanced language features.
Is this a book I read online, or do I need to install anything?It's a book, not software: read it as a website in your browser or download the EPUB. The GitHub repo holds the open-source text itself.
Is the entire book free, or is some of it behind a paywall?The whole book is free and open source. The Plus Edition is a separate paid companion with exclusive content, sold for readers who want to go beyond the free edition.
Is it meant for TypeScript beginners or for experienced developers?Both — it's written for beginners and experienced developers alike, and works as a full learning guide as well as a quick reference.
Is the book really open source — can I reuse or share the content?It's explicitly free and open source, but GitHub detects no standard license (NOASSERTION), so check the repo's license terms before redistributing the content.
What does the paid Plus Edition add over the free book?It is updated for TypeScript 7 and adds practical React typing guidance (components, props, hooks, events, refs) plus real-world TypeScript recipes. It is sold in English and Italian on Amazon.
Where should a beginner start reading?From the beginning: 'TypeScript Introduction' explains what TypeScript is and why to use it, then 'Getting Started With TypeScript' covers installation and configuration before the deep type-system chapters.
How can I support the project if the book is free?Pay what you want (the author suggests $5), sponsor a coffee, or buy the Plus Edition — purchases directly support the continued development and maintenance of the free book.
Creator
gibbok
Size
469.1 MB
Stars
10.4K
Age
4y
Commits · 90 Days