Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deno 将停用 TypeScript 的五个原因 #8100

Merged
merged 2 commits into from Feb 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,38 @@
> * 原文作者:[eliorivero](https://en.gravatar.com/eliorivero)
> * 译文出自:[掘金翻译计划](https://github.com/xitu/gold-miner)
> * 本文永久链接:[https://github.com/xitu/gold-miner/blob/master/article/2021/5-reasons-why-Deno-will-stop-using-TypeScript-StartFunction.md](https://github.com/xitu/gold-miner/blob/master/article/2021/5-reasons-why-Deno-will-stop-using-TypeScript-StartFunction.md)
> * 译者:
> * 校对者:
> * 译者:[zenblo](https://github.com/zenblo)
> * 校对者:[PassionPenguin](https://github.com/PassionPenguin)
>
# 5 reasons why Deno will stop using TypeScript
![image](https://user-images.githubusercontent.com/8282645/109243795-858b9e00-7818-11eb-9779-00cf8282c99f.png)
# Deno 将停用 TypeScript 的五个原因

![image](https://user-images.githubusercontent.com/8282645/109243795-858b9e00-7818-11eb-9779-00cf8282c99f.png)

A document surfaced today pointing that Deno will stop using TypeScript in its internal code, citing several problems with the current environment. Issues mentioned involve TypeScript compiling times, structuring and code organization, among others. Moving forward, Deno will use pure JavaScript for its internal code.
最近有一份流传的文档,说是 Deno 将停止在其内部代码中使用 TypeScript。文档中提到了当前开发环境的几个问题,包括了 TypeScript 编译时间、结构和代码管理等。在未来,Deno 的内部代码将使用原生 JavaScript 进行开发。

## Deno problems with TypeScript
## Deno 使用 TypeScript 的现存问题

The unfavorable situations that the Deno team is currently experiencing while using [TypeScript](https://startfunction.com/tag/typescript) for its internal code are:
目前 Deno 团队在内部代码中使用 [TypeScript](https://startfunction.com/tag/typescript) 时,遇到的问题有如下这些:

- TypeScript compile time when changing files takes several minutes, making continuous compiling an excruciatingly slow process
- The Typescript structure that they’re using in the source files that create the actual Deno executable and the user-facing APIs is creating runtime performance problems
- TypeScript isn’t proving itself helpful to organize Deno code. On the contrary, the Deno team is experiencing the opposite effect. One of the issues mentioned is that they ended up with duplicate independent Body classes in two locations [https://github.com/denoland/deno/issues/4748](https://github.com/denoland/deno/issues/4748)
- The internal code and runtime TypeScript declarations must be manually kept in sync since the TypeScript Compiler isn’t helpful to generate the d.ts files
- They’re maintaining two TS compiler hosts: one for the internal Deno code and another other for external user code even though both have a similar goal
- 当更改文件时,TypeScript 的编译需要几分钟,这使得项目文件的连续编译非常缓慢。
- 在创建实际的 Deno 可执行文件和面向用户的 API 文件时,使用的 TypeScript 结构会造成项目运行的性能问题。
- 事实证明,TypeScript 本身对 Deno 代码管理没有帮助,并且 Deno 团队正经受着相反的效果。在项目的议题列表中就提到一个[问题](https://github.com/denoland/deno/issues/4748):在两个不同的位置产生了相同的独立主体类。
- 必须手动保持内部代码和运行时 TypeScript 声明的同步,因为 TypeScript 编译器对生成 d.ts 文件没有帮助。
- Deno 团队需要去维护两台 TS 编译器主机:一个用于内部代码,另一个用于外部用户代码,尽管两者的目标相似。

## Removing TypeScript in internal Deno code
## Deno 内部代码删除 TypeScript

The [Deno](https://startfunction.com/tag/deno) team aims to remove all build-time TS type checking and bundling for internal Deno code. They’re looking forward to move all the runtime code into a single [JavaScript](https://startfunction.com/category/javascript) file. However, they’ll still use a companion d.ts file to keep the type definitions and documentation.
[Deno](https://startfunction.com/tag/deno) 团队的目标是删除所有构建时 TS 类型检查和内部代码的捆绑。他们打算将所有运行时代码移动到一个 [JavaScript](https://startfunction.com/category/javascript) 文件中。然而,他们还是使用配套的 d.ts 文件来保存类型定义和文档记录。

It’s worth mentioning that Deno will stop using TypeScript only for the internal Deno code: the Deno user code will still be in TypeScript and thus type checked.
值得注意的是,Deno 将只在内部代码中停止使用 TypeScriptDeno 用户代码仍然可以使用 TypeScript,因此会进行类型检查。

While TypeScript is sometimes seen as an improved version of JavaScript, this case is showing that in fact, it’s not. It has flaws like any other language. One of the most important ones is its slow compilation time. While small projects might not see a huge spike in compilation time when switching from pure JavaScript to TypeScript, it will be noticeable in large projects like a complex [React](https://startfunction.com/tag/react) app. Given the large size of its runtime, it’s not surprising that Deno will stop using TypeScript.
虽然 TypeScript 有时被视为 JavaScript 的改进版本,但以上情况表明事实并非如此。它具有任何其他语言一样的缺陷,最重要的问题之一是编译速度慢。从原生 JavaScript 切换到 TypeScript 时,小型项目可能不会在编译时间上出现大幅度的增长,但在大型项目(如复杂的 [React](https://startfunction.com/tag/react) 应用程序)中,它就会很明显。考虑到编译运行时长,Deno 将停止使用 TypeScript 也就不足为奇。

The safety of type checking during development does have its cost at compilation time. It’s not without reason that the TypeScript project has an extensive document on how to address and [improve compilation time](https://github.com/microsoft/TypeScript/wiki/Performance). One of the most interesting approaches is to use [Project References](https://www.typescriptlang.org/docs/handbook/project-references.html), that allows developers to break apart a big TypeScript piece of code into smaller pieces.
项目开发过程进行的安全性类型检查,在编译时是有代价的。TypeScript 项目有一个关于如何解决和[改进编译时间](https://github.com/microsoft/TypeScript/wiki/Performance)的文档,这是有存在意义的。最有趣的方法之一是采取[项目引用](https://www.typescriptlang.org/docs/handbook/project-references.html),它允许开发人员将一个大的 TypeScript 代码片段分解成更小的片段。

## Read more about why Deno will stop using TypeScript
**阅读更多关于 Deno 停用 TypeScript 的原因。**

The complete discussion about the decision to drop TypeScript from the internal Deno code and use JavaScript instead can be found in [this document](https://docs.google.com/document/d/1_WvwHl7BXUPmoiSeD8G83JmS8ypsTPqed4Btkqkn_-4/preview?pru=AAABcrrKL5k*nQ4LS569NsRRAce2BVanXw#), where Ryan Dahl and collaborators discuss the problem, its solution, and how it’s going to be implemented.
关于 Deno 从内部代码中删除 TypeScript 并改用 JavaScript 的完整讨论,可以在[本文](https://docs.google.com/document/d/1_WvwHl7BXUPmoiSeD8G83JmS8ypsTPqed4Btkqkn_-4/preview?pru=AAABcrrKL5k*nQ4LS569NsRRAce2BVanXw#)中找到,Ryan Dahl 与合作者共同讨论了这个问题的解决方案以及如何实现。

> 如果发现译文存在错误或其他需要改进的地方,欢迎到 [掘金翻译计划](https://github.com/xitu/gold-miner) 对译文进行修改并 PR,也可获得相应奖励积分。文章开头的 **本文永久链接** 即为本文在 GitHub 上的 MarkDown 链接。

Expand Down