The project's README from github.com/gibbok/typescript-book. As one markdown file: README.md.
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.
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.
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.
This book has been translated into several languages, including:
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
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.
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 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.
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 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