TypeScript 学习指南 Part 4 关于 Handbook

393 阅读4分钟

开启学习之旅

学习入口

位置:首页 image.png

  • Handbook 手册
  • Playground 演练场
  • Download 下载安装

The TypeScript Handbook

www.typescriptlang.org/docs/handbo…

image.png

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.

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).

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 either the Microsoft Learn JavaScript tutorial or read 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在被引入编程社区20多年后,现在是有史以来最广泛的跨平台语言之一。JavaScript最初是一种小型脚本语言,用于为网页添加琐碎的交互,现在已成为各种规模的前端和后端应用程序的首选语言。虽然用JavaScript编写的程序的大小、范围和复杂性呈指数级增长,但JavaScript语言表达不同代码单元之间关系的能力却没有增长。结合JavaScript相当独特的运行时语义,语言和程序复杂性之间的这种不匹配,使得JavaScript开发 在大规模项目开发中 成为难以管理的任务。

程序员编写的最常见类型的错误可以描述为类型错误:在需要不同类型的值的地方使用了某种值。这可能是由于简单的打字错误、未能理解库的API表面、对运行时行为的错误假设或其他错误造成的。TypeScript的目标是成为JavaScript程序的静态类型检查器typechecker——换句话说,是在代码运行(静态)之前运行的工具,并确保程序的类型正确(typechecked)。

如果你是在没有JavaScript背景的情况下使用TypeScript,并打算将TypeScript作为你的第一语言,我们建议你首先阅读Microsoft Learn JavaScript教程上的文档,或者在Mozilla Web Docs上阅读JavaScript。如果您有其他语言的经验,那么通过阅读手册,您应该能够很快学会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.

    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:

    • Read and understand commonly-used TypeScript syntax and patterns
    • 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.

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.

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.

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.

Get Started 开始

image.png

开始阅读 Handbook 的 The Basics 节之前,我们推荐先阅读完以下几篇导言文章其中之一。

Before getting started with The Basics, 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.

Otherwise(否则,另外), jump to The Basics or grab(抓取、夺得) a copy in Epub or PDF form.

页脚跳转链接:

image.png