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…

这是什么?《The Concise TypeScript Book》:一本免费开源的书,简明扼要地介绍 TypeScript,从强大的类型系统到高级语言特性都有涵盖。
这是在线阅读的书,还是需要安装什么?它是一本书,不是软件:可以在浏览器里当网站阅读,也可以下载 EPUB。GitHub 仓库里放的就是这本书的开源原文。
整本书都免费吗,还是有一部分要付费才能看?整本书免费且开源。Plus 版是一个单独收费的配套版本,包含独家内容,卖给想在免费版基础上进一步深入的读者。
这本书是给 TypeScript 新手看的,还是给有经验的开发者看的?两者都适合——它是为新手和有经验的开发者共同编写的,既可以作为完整的学习指南,也可以当快速参考手册用。
这本书真的开源吗——我能复用或分享其中的内容吗?它明确是免费开源的,但 GitHub 没有检测到标准许可证(NOASSERTION),所以在转发或再分发内容之前,请先查看仓库里的许可条款。
付费的 Plus 版比免费版多了什么?它针对 TypeScript 7 进行了更新,增加了实用的 React 类型指导(组件、props、hooks、事件、refs),还收录了不少真实场景的 TypeScript 实用技巧。在 Amazon 上有英文版和意大利文版出售。
新手应该从哪里开始读?从头开始:'TypeScript Introduction' 一章解释了 TypeScript 是什么、为什么要用它,接着 'Getting Started With TypeScript' 讲安装和配置,之后才进入深入的类型系统章节。
书既然免费,我能怎么支持这个项目?随心付(作者建议 $5)、请作者喝杯咖啡,或者购买 Plus 版——这些收入都会直接用于免费书的持续开发和维护。
Creator
gibbok
Size
469.1 MB
Stars
10.4K
Age
4y
Commits · 90 Days