TypeScript入门到精通——什么是 TypeScript ?
什么是 TypeScript ?
https://en.wikipedia.org/wiki/TypeScript
一、介绍 TypeScript
TypeScript is a free and open-source high-level programming language developed by Microsoft that adds static typing with optional type annotations to JavaScript. It is designed for the development of large applications and transpiles to JavaScript.Because TypeScript is a superset of JavaScript, all JavaScript programs are syntactically valid TypeScript, but they can fail to type-check for safety reasons.
翻译: TypeScript 是微软开发的免费开源高级语言,它为 JavaScript 添加了带有可选类型注释的静态类型。它是为开发大型应用程序和转换为 JavaScript 而设计的。因为 TypeScript 是 JavaScript 的超集,所有的 JavaScript 程序在语法上都是有效的 TypeScript,但出于安全原因,它们可能无法进行类型检查。
TypeScript may be used to develop JavaScript applications for both client-side and server-side execution (as with Node.js or Deno). Multiple options are available for transpilation. The default TypeScript Compiler can be used or the Babel compiler can be invoked to convert TypeScript to JavaScript.
翻译: TypeScript 可用于开发用于客户端和服务器端执行的 JavaScript 应用程序(与 Node.js 或 Deno 一样)。有多个可用于翻译的选项。可以使用默认的 TypeScript 编译器 ,也可以调用 Babel 编译器将 TypeScript 转换为 JavaScript。
TypeScript supports definition files that can contain type information of existing JavaScript libraries, much like C++ header files can describe the structure of existing object files. This enables other programs to use the values defined in the files as if they were statically typed TypeScript entities. There are third-party header files for popular libraries such as jQuery, MongoDB, and D3.js. TypeScript headers for the Node.js library modules are also available, allowing development of Node.js programs within TypeScript.
翻译: TypeScript 支持定义文件,这些文件可以包含现有 JavaScript 库的类型信息,就像 C++ 头文件可以描述现有对象文件的结构一样。这使其他程序能够像使用静态类型的 TypeScript 实体一样使用文件中定义的值。流行的库(如 jQuery、 MongoDB 和 D3.js)有第三方头文件。还可以使用 Node.js 库模块的 TypeScript 头文件,从而允许在 TypeScript 中开发 Node.js 程序。
The TypeScript compiler is itself written in TypeScript and compiled to JavaScript. It is licensed under the Apache License 2.0. Anders Hejlsberg, lead architect of C# and creator of Delphi and Turbo Pascal, has worked on the development of TypeScript.
翻译: TypeScript 编译器本身是用 TypeScript 编写并编译成 JavaScript 的。它是根据 Apache License 2.0授权的。安德斯·海尔斯伯格是 C # 的首席架构师,也是 Delphi 和 Turbo Pascal 的创建者,他一直致力于 TypeScript 的开发。
二、历史
TypeScript was released to the public in October 2012, with version 0.8, after two years of internal development at Microsoft Soon after the initial public release, Miguel de Icaza praised the language itself, but criticized the lack of mature IDE support apart from Microsoft Visual Studio, which was not available on Linux and OS X at that time. As of April 2021 there is support in other IDEs and text editors, including Emacs, Vim, WebStorm, Atom and Microsoft's own Visual Studio Code. TypeScript 0.9, released in 2013, added support for generics.
翻译: TypeScript 编译器本身是用 TypeScript 在微软内部开发了两年之后,于 2012 年 10 月发布了 0.8 版本。在首次公开发布后不久,Miguel de Icaza 称赞了这种语言本身,但批评除了微软 Visual Studio 之外缺乏成熟的 IDE 支持,当时 Linux 和 OS X 都没有这种支持。截至2021年4月,其他 IDE 和文本编辑器也提供了支持,包括 Emacs、 Vim、 WebStorm、 Atom 和微软自己的 Visual Studio Code。2013年发布的 TypeScript 0.9 增加了对泛型的支持。
TypeScript 1.0 was released at Microsoft's Build developer conference in 2014. Visual Studio 2013 Update 2 provides built-in support for TypeScript. Further improvement were made in July 2014, when the development team announced a new TypeScript compiler, asserted to have a five-fold performance increase. Simultaneously, the source code, which was initially hosted on CodePlex, was moved to GitHub.
翻译: TypeScript 1.0 是在2014年微软的 Build 开发者大会上发布的。 VisualStudio2013Update2 提供了对 TypeScript 的内置支持。2014年7月,开发团队宣布了一个新的 TypeScript 编译器,声称性能提高了5倍。与此同时,最初托管在 CodePlex 上的源代码被转移到 GitHub。
On 22 September 2016, TypeScript 2.0 was released, introducing several features, including the ability for programmers to optionally enforce null safety, to mitigate what's sometimes referred to as the billion-dollar mistake.
翻译: 2016年9月22日,TypeScript 2.0 发布,引入了一些特性,包括程序员可以选择强制执行 null 安全,以减轻有时被称为十亿美元的错误。
TypeScript 3.0 was released on 30 July 2018, bringing many language additions like tuples in rest parameters and spread expressions, rest parameters with tuple types, generic rest parameters and so on.
翻译: TypeScript 3.0 于 2018 年 7 月 30 日 发布,增加了很多语言,比如静止参数和扩展表达式中的元组,带有元组类型的静止参数,通用的静止参数等等。
TypeScript 4.0 was released on 20 August 2020. While 4.0 did not introduce any breaking changes, it added language features such as Custom JSX Factories and Variadic Tuple Types.
翻译: TypeScript 4.0 于2020年8月20日发布。虽然 4.0 没有引入任何突破性的改变,但它增加了诸如自定义 JSX 工厂和变量元组类型等语言特性。
TypeScript 5.0 was released on 16 March 2023 and included support for decorators.
翻译: TypeScript 5.0 于 2023 年 3 月 16 日发布,其中包括对装饰器的支持。
三、Design
TypeScript originated from the shortcomings of JavaScript for the development of large-scale applications both at Microsoft and among their external customers. Challenges with dealing with complex JavaScript code led to demand for custom tooling to ease developing of components in the language.
翻译: TypeScript 起源于 JavaScript 在微软和外部客户之间开发大规模应用程序时的缺点。处理复杂 JavaScript 代码的挑战导致了对自定义工具的需求,以简化语言中组件的开发。
TypeScript developers sought a solution that would not break compatibility with the standard and its cross-platform support. Knowing that the current ECMAScript standard proposal promised future support for class-based programming, TypeScript was based on that proposal. That led to a JavaScript compiler with a set of syntactical language extensions, a superset based on the proposal, that transforms the extensions into regular JavaScript. In this sense, the class feature of TypeScript was a preview of what to expect from ECMAScript 2015. A unique aspect not in the proposal, but added to TypeScript, is optional static typing (also known as gradual typing) that enables static language analysis to facilitate tooling and IDE support.
翻译: TypeScript 开发人员寻求的解决方案不会破坏与标准及其跨平台支持的兼容性。当前的 ECmascript 标准提案承诺未来会支持类别基础编程,TypeScript 就是基于这个提案。这使得 JavaScript 编译器具有一组语法语言扩展,这是一个基于提议的超集,可以将扩展转换为常规 JavaScript。从这个意义上说,TypeScript 的类特性是对 ECMAScript 2015的预览。一个独特的方面不在提案中,但添加到 TypeScript,是可选的静态类型(也称为渐进类型) ,使静态语言分析,以促进工具和 IDE 支持。