About this Handbook
关于本手册
Over 20 years after its introduction to the programming community, JavaScript is now one of the most widespread cross-platform languages ever created. Starting as a small scripting language for adding trivial interactivity to webpages, JavaScript has grown to be a language of choice for both frontend and backend applications of every size. While the size, scope, and complexity of programs written in JavaScript has grown exponentially, the ability of the JavaScript language to express the relationships between different units of code has not. Combined with JavaScript’s rather peculiar runtime semantics, this mismatch between language and program complexity has made JavaScript development a difficult task to manage at scale.
在引入编程社区20多年后,JavaScript现在是有史以来最广泛使用的跨平台语言之一。最初,JavaScript是一种用于向网页添加细碎交互的很小的脚本语言,现在它已成为各种规模的前端和后端应用程序的首选语言。虽然用JavaScript编写的程序的大小、范围和复杂性呈指数级增长,但JavaScript语言处理不同单位代码之间关系的能力却没有增长。再加上JavaScript特有的运行时语义,这种语言和程序复杂性之间的不匹配使得JavaScript开发很难进行大规模管理。
The most common kinds of errors that programmers write can be described as type errors: a certain kind of value was used where a different kind of value was expected. This could be due to simple typos, a failure to understand the API surface of a library, incorrect assumptions about runtime behavior, or other errors. The goal of TypeScript is to be a static typechecker for JavaScript programs - in other words, a tool that runs before your code runs (static) and ensures that the types of the program are correct (typechecked).
程序员编写的最常见的错误类型可能就是类型错误:在需要不同类型值的地方使用了特定类型的值。这可能是由于简单的拼写错误、错误理解一个库API的表面、对运行时行为的错误假设或其他错误造成的。TypeScript的目标是成为JavaScript程序的静态类型检查器——换句话说,一个在你的代码运行之前运行的静态工具,并确保程序的类型是正确的。
If you are coming to TypeScript without a JavaScript background, with the intention of TypeScript being your first language, we recommend you first start reading the documentation on JavaScript at the Mozilla Web Docs. If you have experience in other languages, you should be able to pick up JavaScript syntax quite quickly by reading the handbook.
如果你没有学过JavaScript,想让TypeScript成为你的第一个语言,我们建议你第一次开始阅读文档的JavaScript在Mozilla Web文档。如果你有其它语言经验,你应该能够很快通过阅读MDN学会JavaScript语法。
How is this Handbook Structured
这本手册的结构
The handbook is split into two sections:
手册分为两个部分:
- The Handbook
- 手册
The TypeScript Handbook is intended to be a comprehensive document that explains TypeScript to everyday programmers. You can read the handbook by going from top to bottom in the left-hand navigation.
TypeScript手册旨在成为一个向程序员日常开发中解释TypeScript的综合性文档。你可以在左边的导航栏上从上到下阅读手册。
You should expect each chapter or page to provide you with a strong understanding of the given concepts. The TypeScript Handbook is not a complete language specification, but it is intended to be a comprehensive guide to all of the language’s features and behaviors.
A reader who completes the walkthrough should be able to:
你应该期待每一章或每一页都能让你对所给的概念有一个深刻的理解。Typescript手册并不是一个完整的语言规范,但它旨在成为一个全面的指南,介绍该语言的所有特性和行为。
完成本攻略的读者应该能够:
- Read and understand commonly-used TypeScript syntax and patterns
- 阅读和理解常用的TypeScript语法和模式
- Explain the effects of important compiler options
- 解释编译器重要项的作用。
- Correctly predict type system behavior in most cases
- 在大多数情况下正确预测类型系统的行为
In the interests of clarity and brevity, the main content of the Handbook will not explore every edge case or minutiae of the features being covered. You can find more details on particular concepts in the reference articles.
为了清晰和简洁,手册的主要内容不会探讨每一个边缘案例或被覆盖的特性的细节。您可以在参考文章中找到关于特定概念的更多细节
- Reference Files
- 参考文件
The reference section below the handbook in the navigation is built to provide a richer understanding of how a particular part of TypeScript works. You can read it top-to-bottom, but each section aims to provide a deeper explanation of a single concept - meaning there is no aim for continuity.
手册下面的参考部分是为了让读者更深入地了解TypeScript的某个特定部分是如何工作的。您可以从头到尾地阅读它,但每一节都旨在对单概念提供更深层次的解释——这意味着不是连续性的。
Non-Goals
需求
The Handbook is also intended to be a concise document that can be comfortably read in a few hours. Certain topics won’t be covered in order to keep things short.
手册也打算成为一份简明的文件,可以在几个小时内轻松地阅读。为了使内容简短,某些主题将不被涵盖。
Specifically, the Handbook does not fully introduce core JavaScript basics like functions, classes, and closures. Where appropriate, we’ll include links to background reading that you can use to read up on those concepts.
具体来说,手册没有完全介绍JavaScript的核心基础,如函数、类和闭包。在适当的情况下,我们会给出背景链接,你可以用它来阅读这些概念。
The Handbook also isn’t intended to be a replacement for a language specification. In some cases, edge cases or formal descriptions of behavior will be skipped in favor of high-level, easier-to-understand explanations. Instead, there are separate reference pages that more precisely and formally describe many aspects of TypeScript’s behavior. The reference pages are not intended for readers unfamiliar with TypeScript, so they may use advanced terminology or reference topics you haven’t read about yet.
手册也不是用来代替语言规范的。在某些情况下,对于极个别情况或很正式的说明将会被跳过,而采用更高级、更容易理解的解释。相反,有单独的参考页面,更精确和正式地描述TypeScript行为的许多方面。参考页面不是为不熟悉Typescript的读者准备的,所以他们可能会使用高级术语或你没有读过的参考主题。
Finally, the Handbook won’t cover how TypeScript interacts with other tools, except where necessary. Topics like how to configure TypeScript with webpack, rollup, parcel, react, babel, closure, lerna, rush, bazel, preact, vue, angular, svelte, jquery, yarn, or npm are out of scope - you can find these resources elsewhere on the web.
最后,手册中没有提到TypeScript如何与其他工具交互,除非有必要。像如何用webpack、rollup、parcel、react、babel、closure、lerna、rush、bazel、preact、vue、angular、slevelte、jquery、yarn或npm来配置TypeScript之类的主题不在讨论范围内——你可以在网上其他地方找到这些资源。
Get Started
开始
Before getting started with Basic Types, we recommend reading one of the following introductory pages. These introductions are intended to highlight key similarities and differences between TypeScript and your favored programming language, and clear up common misconceptions specific to those languages.
在开始学习基本类型之前,我们建议阅读以下引导页之一。这些引导页旨在强调TypeScript和你喜欢的编程语言之间的主要相似点和不同点,并澄清这些语言特有的常见误解。
- TypeScript for New Programmers
- TypeScript for JavaScript Programmers
- TypeScript for OOP Programmers
- TypeScript for Functional Programmers
Otherwise, jump to Basic Types or grab a copy in Epub or PDF form.
