TypeScript in Action: A Practical Guide cover

TypeScript in Action: A Practical Guide

Rating 3.0
Word count
178K words
Chapters
14
Series
Practical Guide
ISBN
9787111626701

Tags

Summary

TypeScript in Action: A Practical Guide is an introductory and practical front-end technology book written by Hu Huanming and published by China Machine Press in 2019. It is divided into a fundamentals section and a practice section, with 11 chapters in total. The fundamentals section begins with the relationship between TypeScript, JavaScript, and ECMAScript, introduces environment setup (Node.js, npm and Yarn, VS Code configuration) and the first Hello World, then systematically covers basic and advanced types (intersection types, union types, type guards, type aliases, index types and mapped types, type inference, etc.), functions (callbacks, Promises, async/await, overloading), interfaces and classes (function types, indexable types, inheritance, accessors, abstract classes), and namespaces and modules (single-file and multi-file namespaces, exports and imports, external modules). The practice section uses a single "reminders/list" application as its main thread, guiding readers through building a command-line weather query tool (Commander.js, network requests), an Express backend service (database connection, data models, CRUD interfaces), a React desktop website (React Router, Redux, Redux Persist, Jest testing), a React Native client, a Vue 5 web page (vue-class-component), and a WeChat mini program (WePY project and TypeScript configuration, native API optimization). The final chapter explains the path for migrating from JavaScript or Flow to TypeScript, as well as contributing type declaration files to the community (DefinitelyTyped) and keeping up with version updates. Each chapter includes a summary and assignments, suitable for learning by doing.

Editor's review

市面上讲 TypeScript 语法的书不少,真正把“学过语法”推进到“能在项目里用起来”的却不多。本书的可贵之处在于结构清晰:前四章用紧凑的篇幅把类型系统、函数、接口与类、命名空间与模块讲透,每个知识点都配有可直接运行的示例;后七章则用一个贯穿始终的“提醒事项/列表”应用,在命令行、Express、React、React Native、Vue、微信小程序六种场景中反复演练,让读者看到同一套类型思维如何在不同框架下落地。作者胡桓铭曾是 ThoughtWorks 前端工程师,并参与过 DefinitelyTyped 的类型声明维护,因此书中对 tsconfig 配置、TSLint、Husky、测试与类型声明文件这些工程细节着墨较多,这些恰恰是初学者最容易卡住的地方。每章末尾的小结与作业也很实用,适合作为团队内训或自学打卡的教材。需要说明的是,本书出版于 2019 年,示例基于当时的工具链版本,今天动手实践时需留意依赖升级带来的差异;但这并不影响它作为理解 TypeScript 工程化思路的入门读物。

Who it's for

A good fit for

  • 有 JavaScript 基础、想把项目迁移到 TypeScript 的前端开发者
  • 刚入门前端、希望系统掌握类型系统与工程配置的学生或转行者
  • 需要在 React、Vue、小程序等多种技术栈中统一使用 TypeScript 的全栈工程师
  • 负责团队技术培训、想找一本有作业与案例的教材的技术负责人

Not a good fit for

  • 完全没有 JavaScript 与命令行基础的零起点读者
  • 希望直接学习最新 TypeScript 版本新特性与最新框架用法的读者,本书案例基于 2019 年前后的工具链
  • 只想查阅语法速查表、不打算跟着敲代码的读者

Reading tips

  1. 先通读基础篇并动手敲完每章示例,尤其是第2章的类型推导与类型保护,这是后续实战的地基。
  2. 实战篇不必按顺序全做,可挑选与自己技术栈相关的 2—3 章精读,其余章节浏览架构思路即可。
  3. 动手时注意依赖版本差异:Node、React、Vue CLI 等已多次大版本更新,遇到报错优先查阅官方文档而非照抄命令。
  4. 读完后拿一个自己现有的 JavaScript 小项目做迁移练习,配合第11章的迁移路径与 DefinitelyTyped 贡献流程。

About the publisher

China Machine Press China · Founded in 1950

In addition to science and technology and professional publishing, the books in our catalog from China Machine Press also reflect a sustained focus on psychology, computing, management, finance and economics, and social sciences. In psychology, the catalog includes works by C. G. Jung and introductions to analytical psychology, as well as applied topics such as stress and health, and addiction and healing. In computing, it features Structure and Interpretation of Computer Programs (JavaScript Edition). Management and finance titles include Administrative Behavior (4th Edition), The Price of Inequality (Collector's Edition), and This Time Is Different: Eight Centuries of Financial Folly (Commemorative Edition). In the philosophy and history of science, there is The Worldview: The Third Edition. Relevant authors include C. G. Jung, William McGuire, Sonu Shamdasani, and Gabor Maté. Public information is limited; the above summarizes the publisher's profile based solely on the books in our catalog.

Contents

  1. Preface
  2. Fundamentals
  3. Chapter 1 Hello TypeScript: Introduction (JavaScript and ECMAScript, TypeScript), Setting Up the Environment, Visual Studio Code, Hello World, Chapter Summary and Assignments
  4. Chapter 2 Types and Functions: Basic Types (variable declarations, generics, enums, symbol, iterator and generator), Advanced Types (interface, intersection and union types, type guards and discriminated unions, typeof and instanceof, type aliases, literal types, index types and mapped types, type inference), Functions (definition, parameters, callbacks and Promises, async and await, overloading)
  5. Chapter 3 Interfaces and Classes: Interface definition, function types, indexable types, extending interfaces; Class definition, implementing interfaces, inheritance, accessors, readonly properties, class methods and static properties, abstract classes
  6. Chapter 4 Namespaces and Modules: Single-file and multi-file namespaces, aliases, external namespaces; Exports and imports, generating modules, external modules
  7. Practice
  8. Chapter 5 Command-Line Application in Practice: Weather Query—Creating a Project (TSConfig, TSLint, Git), Commander.js, Handling Network Requests
  9. Chapter 6 Express in Practice: Backend Service—Initializing the Project and Husky, Connecting to the Database and Data Models, Express CRUD Interfaces
  10. Chapter 7 React in Practice: Desktop Website—create-react-app and TypeScript Configuration, React-Router and Redux Architecture, Editing Reminders, Implementing the List, Jest Testing
  11. Chapter 8 React Native in Practice: Client Development—Setting Up the Development Environment, Creating a Project, React Navigation and Redux Architecture, The List Page
  12. Chapter 9 Vue in Practice: HTML 5 Web Development—Creating a Vue Project, Writing TypeScript Code, vue-class-component, Network Requests and the List Page
  13. Chapter 10 Mini Program in Practice—Creating a Mini Program and WePY Project, Configuring TypeScript, Entry File, WePY Pages and Components, Optimizing for Native APIs
  14. Chapter 11 Project Migration and Community Contribution—Migrating from JavaScript to TypeScript, Migrating from Flow to TypeScript, Contributing Type Files, Following Updates

FAQ

这本书适合完全没有编程经验的人吗?
不太适合。书中默认读者已掌握 JavaScript 基本语法、会用 npm 和命令行,开篇即进入环境配置与类型讲解。零基础读者建议先补 JavaScript 与 Node.js 基础,再回来阅读。
书中的示例代码现在还能跑起来吗?
核心的类型语法示例基本可用,但实战篇涉及 create-react-app、Vue CLI、WePY 等工具,这些工具多年来版本变化较大,按书中命令操作可能报错。建议以理解思路为主,具体配置参考各工具当前官方文档。
这本书和《TypeScript入门与实战》有什么区别?
两书定位相近但侧重不同。本书用 11 章、约 178 千字的篇幅,以同一应用贯穿六种技术栈的实战为主线;钟胜平的《TypeScript入门与实战》篇幅更大,对类型系统与声明文件的讲解更深入细致。可按自己更需要广度还是深度来选择。
读完能到什么水平?
可以独立为中小型前端项目配置 TypeScript、编写带类型的组件与模块,并理解从 JavaScript 或 Flow 迁移的基本路径。要熟练应对大型项目的复杂类型设计,还需要继续阅读官方手册并多做实践。

Comments

Find this book

This site is an index: you start “Search all sources” in your browser, and the entries it lists all point to third-party sites; please judge their availability yourself.

Top rated in the same category