我应该用打印稿吗?或者我可以用ES6?

时间:2022-10-03 15:24:56

My daily job is client developer using AngularJS. We are evaluating if we want to go with TypeScript. I did some research on typescript and almost every JavaScript package I need must have definition type files. I found that is not very convenient, especially if I would like to try something new and they don't have the definition for it. Its really frustrating. (Even the current jQuery definition gives me some problems if I want to use typescript 1.5 beta). I started looking at ES6 and it looks similar to TypeScript. Should I just use ES6 instead? Also, I heard angular 2 will have full support for TypeScript, will that be one reason I should stay with it?

我的日常工作是使用AngularJS开发客户端。我们正在评估是否要使用打字稿。我对打字稿和几乎所有我需要的JavaScript包都必须有定义类型文件进行了一些研究。我发现这不是很方便,特别是如果我想尝试一些新的东西,他们没有定义。它真的很令人沮丧。(如果我想使用typescript 1.5 beta,即使是当前的jQuery定义也会给我带来一些问题)。我开始研究ES6,它看起来很像打字稿。我应该用ES6代替吗?而且,我听说角2会完全支持打字稿,这是我应该留下来的一个原因吗?

2 个解决方案

#1


106  

I've been using Typescript in my current angular project for about a year and a half and while there are a few issues with definitions every now and then the DefinitelyTyped project does an amazing job at keeping up with the latest versions of most popular libraries.

我在当前的角度项目中使用打字稿已经有一年半的时间了,虽然时不时会有一些关于定义的问题,但是这个确定类型的项目在跟上最流行的库的最新版本方面做得非常出色。

Having said that there is a definite learning curve when transition from vanilla JavaScript to TS and you should take into account the ability of you and your team to make that transition. Also if you are going to be using angular 1.x most of the examples you will find online will require you to translate them from JS to TS and overall there are not a lot of resources on using TS and angular 1.x together right now.

说到从普通的JavaScript到TS有一个明确的学习曲线,您应该考虑到您和您的团队进行这种转换的能力。如果你要用角1。你在网上找到的大多数例子都需要你把它们从JS翻译成TS,总的来说,使用TS和角1的资源并不多。x在一起现在。

If you plan on using angular 2 there are a lot of examples using TS and I think the team will continue to provide most of the documentation in TS, but you certainly don't have to use TS to use angular 2.

如果你计划使用角2,有很多使用角2的例子我想团队会继续提供大部分关于角2的文档,但是你肯定不需要用角2。

ES6 does have some nice features and I personally plan on getting more familiar with it but I would not consider it a production ready language at this point. Mainly due to a lack of support by current browsers. See this SO answer for more details. Of course you can write your code in ES6 and use a transpiler to get it to ES5, which seems to be the popular thing to do right now.

ES6确实有一些不错的特性,我个人计划更熟悉它,但我现在不认为它是一种可用于生产的语言。主要是由于缺乏当前浏览器的支持。更多细节见此答案。当然,您可以在ES6中编写代码,并使用一个传输器将其传输到ES5,这似乎是当前流行的做法。

Overall I think the answer would come down to what you and your team are comfortable learning. I personally think both TS and ES6 will have good support and long futures, I prefer TS though because you tend to get language features quicker and right now the tooling support (in my opinion) is a little better.

总的来说,我认为答案将归结于你和你的团队在学习什么。我个人认为TS和ES6都将有很好的支持和长远的未来,尽管我更喜欢TS,因为您倾向于更快地获得语言特性,现在工具支持(在我看来)更好一些。

#2


638  

Decision tree between ES5, ES6 and TypeScript

ES5、ES6和TypeScript之间的决策树

Do you mind having a build step?

你介意有一个构建步骤吗?

  • Yes - Use ES5
  • 是的,使用ES5
  • No - keep going
  • 不,继续

Do you want to use types?

您想要使用类型吗?

  • Yes - Use TypeScript
  • 是的,使用打印稿
  • No - Use ES6
  • 不——使用ES6

More Details

ES5 is the JavaScript you know and use in the browser today it is what it is and does not require a build step to transform it into something that will run in today's browsers

ES5是你现在在浏览器中使用的JavaScript,它就是它,不需要构建步骤就可以将它转换成在当今浏览器中运行的东西

ES6 (also called ES2015) is the next iteration of JavaScript, but it does not run in today's browsers. There are quite a few transpilers that will export ES5 for running in browsers. It is still a dynamic (read: untyped) language.

ES6(也称为ES2015)是JavaScript的下一个迭代,但是它并不在当今的浏览器中运行。有相当多的传输器将导出ES5以便在浏览器中运行。它仍然是一种动态(读:无类型)语言。

TypeScript provides an optional typing system while pulling in features from future versions of JavaScript (ES6 and ES7).

TypeScript提供了一个可选的输入系统,同时从JavaScript的未来版本(ES6和ES7)中提取特性。

Note: a lot of the transpilers out there (i.e. babel, TypeScript) will allow you to use features from future versions of JavaScript today and exporting code that will still run in today's browsers.

注意:很多传输器(比如babel、TypeScript)将允许您使用当前JavaScript的未来版本的特性,并导出仍然在当前浏览器中运行的代码。

#1


106  

I've been using Typescript in my current angular project for about a year and a half and while there are a few issues with definitions every now and then the DefinitelyTyped project does an amazing job at keeping up with the latest versions of most popular libraries.

我在当前的角度项目中使用打字稿已经有一年半的时间了,虽然时不时会有一些关于定义的问题,但是这个确定类型的项目在跟上最流行的库的最新版本方面做得非常出色。

Having said that there is a definite learning curve when transition from vanilla JavaScript to TS and you should take into account the ability of you and your team to make that transition. Also if you are going to be using angular 1.x most of the examples you will find online will require you to translate them from JS to TS and overall there are not a lot of resources on using TS and angular 1.x together right now.

说到从普通的JavaScript到TS有一个明确的学习曲线,您应该考虑到您和您的团队进行这种转换的能力。如果你要用角1。你在网上找到的大多数例子都需要你把它们从JS翻译成TS,总的来说,使用TS和角1的资源并不多。x在一起现在。

If you plan on using angular 2 there are a lot of examples using TS and I think the team will continue to provide most of the documentation in TS, but you certainly don't have to use TS to use angular 2.

如果你计划使用角2,有很多使用角2的例子我想团队会继续提供大部分关于角2的文档,但是你肯定不需要用角2。

ES6 does have some nice features and I personally plan on getting more familiar with it but I would not consider it a production ready language at this point. Mainly due to a lack of support by current browsers. See this SO answer for more details. Of course you can write your code in ES6 and use a transpiler to get it to ES5, which seems to be the popular thing to do right now.

ES6确实有一些不错的特性,我个人计划更熟悉它,但我现在不认为它是一种可用于生产的语言。主要是由于缺乏当前浏览器的支持。更多细节见此答案。当然,您可以在ES6中编写代码,并使用一个传输器将其传输到ES5,这似乎是当前流行的做法。

Overall I think the answer would come down to what you and your team are comfortable learning. I personally think both TS and ES6 will have good support and long futures, I prefer TS though because you tend to get language features quicker and right now the tooling support (in my opinion) is a little better.

总的来说,我认为答案将归结于你和你的团队在学习什么。我个人认为TS和ES6都将有很好的支持和长远的未来,尽管我更喜欢TS,因为您倾向于更快地获得语言特性,现在工具支持(在我看来)更好一些。

#2


638  

Decision tree between ES5, ES6 and TypeScript

ES5、ES6和TypeScript之间的决策树

Do you mind having a build step?

你介意有一个构建步骤吗?

  • Yes - Use ES5
  • 是的,使用ES5
  • No - keep going
  • 不,继续

Do you want to use types?

您想要使用类型吗?

  • Yes - Use TypeScript
  • 是的,使用打印稿
  • No - Use ES6
  • 不——使用ES6

More Details

ES5 is the JavaScript you know and use in the browser today it is what it is and does not require a build step to transform it into something that will run in today's browsers

ES5是你现在在浏览器中使用的JavaScript,它就是它,不需要构建步骤就可以将它转换成在当今浏览器中运行的东西

ES6 (also called ES2015) is the next iteration of JavaScript, but it does not run in today's browsers. There are quite a few transpilers that will export ES5 for running in browsers. It is still a dynamic (read: untyped) language.

ES6(也称为ES2015)是JavaScript的下一个迭代,但是它并不在当今的浏览器中运行。有相当多的传输器将导出ES5以便在浏览器中运行。它仍然是一种动态(读:无类型)语言。

TypeScript provides an optional typing system while pulling in features from future versions of JavaScript (ES6 and ES7).

TypeScript提供了一个可选的输入系统,同时从JavaScript的未来版本(ES6和ES7)中提取特性。

Note: a lot of the transpilers out there (i.e. babel, TypeScript) will allow you to use features from future versions of JavaScript today and exporting code that will still run in today's browsers.

注意:很多传输器(比如babel、TypeScript)将允许您使用当前JavaScript的未来版本的特性,并导出仍然在当前浏览器中运行的代码。