简体   繁体   English

Node.js 的 TypeScript?

[英]TypeScript for Node.js?

Is it possible to write server app using Node.js with TypeScript.是否可以使用 Node.js 和 TypeScript 编写服务器应用程序。

Are there plans in Node.js team to support TypeScript? Node.js 团队是否有计划支持 TypeScript?

How to you think what kind of benefits it may bring?您如何认为它可能带来什么样的好处?

Is it possible to write server app using Node.js with TypeScript.是否可以使用 Node.js 和 TypeScript 编写服务器应用程序。

There is a compiler that can compile TypeScript to ECMAScript.有一个编译器可以将 TypeScript 编译为 ECMAScript。 It is called tsc and you can find it at the TypeScript homepage .它被称为tsc ,您可以在TypeScript 主页上找到它。

Since Node.js can execute ECMAScript, you can trivially write a server app using Node.js with TypeScript by simply using tsc to compile TypeScript to ECMAScript.由于 Node.js 可以执行 ECMAScript,因此您只需使用tsc将 TypeScript 编译为 ECMAScript,就可以轻松地使用 Node.js 和 TypeScript 编写服务器应用程序。

You can do this with every language for which a compiler to ECMAScript exists, actually.实际上,您可以对存在 ECMAScript 编译器的每种语言执行此操作。 PureScript , CoffeeScript , CokeScript , Scala , Elm , Ruby , Java , F♯, C♯, and many many others . PureScriptCoffeeScriptCokeScriptScalaElmRubyJava 、 F♯、 C♯ 和许多其他的

There's also Emscripten , a compiler backend for LLVM that compiles to ECMAScript.还有Emscripten ,这是一个用于 LLVM 的编译器后端,可编译为 ECMAScript。 This means, you can compile any language for which an LLVM frontend exists, eg Rust, Swift, Objective-C, Go, C++, C, etc., to ECMAScript and thus write Node.js apps in them.这意味着,您可以将任何存在 LLVM 前端的语言(例如 Rust、Swift、Objective-C、Go、C++、C 等)编译为 ECMAScript,从而在其中编写 Node.js 应用程序。

Also, you can use Emscripten to compile any interpreter written in Rust, Swift, Objective-C, Go, C++, C, etc. to ECMAScript, run that interpreter on Node.js and thus write your Node.js app in any language for which an interpreter written in C, C++, etc. exists.此外,您可以使用 Emscripten 将任何用 Rust、Swift、Objective-C、Go、C++、C 等编写的解释器编译为 ECMAScript,在 Node.js 上运行该解释器,从而以任何语言编写您的 Node.js 应用程序存在用 C、C++ 等编写的解释器。

Are there plans in Node.js team to support TypeScript? Node.js 团队是否有计划支持 TypeScript?

There is no need since you can already write Node.js apps in TypeScript and lots of other languages today.没有必要,因为您现在已经可以使用 TypeScript 和许多其他语言编写 Node.js 应用程序。

How to you think what kind of benefits it may bring?您如何认为它可能带来什么样的好处?

The same benefits and drawbacks writing anything in TypeScript brings.用 TypeScript 编写任何东西都会带来同样的好处和缺点。

TL;DR TL; 博士

  1. Yes, you can.是的你可以。
  2. It's already supported已经支持了

Benefits好处

  • Better maintence更好的维护
  • Better productivity更好的生产力
  • Type Safe类型安全
  • ... ...

There's an article on Medium about.一篇关于 Medium 的文章

If you read the docs of NestJS , You would see如果你阅读NestJS的文档,你会看到

Nest is a framework for building efficient, scalable Node.js server-side applications. Nest 是一个用于构建高效、可扩展的 Node.js 服务器端应用程序的框架。 It uses modern JavaScript, is built with TypeScript (preserves compatibility with pure JavaScript) and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Reactive Programming).它使用现代 JavaScript,使用 TypeScript(保留与纯 JavaScript 的兼容性)构建,并结合了 OOP(面向对象编程)、FP(函数式编程)和 FRP(函数式响应式编程)的元素。

See docs查看文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM