简体   繁体   English

现代浏览器中的 TypeScript 支持 [关闭]

[英]TypeScript support in modern browsers [closed]

I've just read some advertisement information related to TypeScript and besides that I have no experience with this superset of JavaScript. So I have some basic questions:我刚刚阅读了一些与 TypeScript 相关的广告信息,除此之外我对 JavaScript 的超集没有任何经验。所以我有一些基本问题:

  1. What is the status of native TypeScript support by the modern browsers?现代浏览器对本机 TypeScript 的支持情况如何?

  2. What are the positions of the major browser vendors for the future support of TypeScript natively?对于未来原生支持TypeScript,各大浏览器厂商的立场是什么?

  3. What is the relation between TypeScript and ECMAScript 6 and does TypeScript provide much more features than ECMAScript 6? TypeScript 和ECMAScript 6之间有什么关系,TypeScript 提供的功能是否比 ECMAScript 6 多得多?

Native support原生支持

Native support can be added quite easily eg https://github.com/basarat/typescript-script adds support for script tags (although this adds 6MB of supporting JS to a page).可以很容易地添加本机支持,例如https://github.com/basarat/typescript-script添加对脚本标签的支持(尽管这为页面添加了 6MB 的支持 JS)。 However there is a performance hit in compiling TypeScript to JavaScript and for the best performance it is best to precompile and execute the compiled JavaScript in the browsers.然而,将 TypeScript 编译为 JavaScript 会降低性能,为了获得最佳性能,最好在浏览器中预编译和执行已编译的 JavaScript。

Browser vendors have no plans to add native TypeScript support.浏览器供应商没有计划添加原生 TypeScript 支持。 The only native languages common across browsers are JavaScript and WebAssembly.浏览器中唯一通用的本地语言是 JavaScript 和 WebAssembly。 TypeScript can be transpiled to either and run in the browsers so its not a blocker. TypeScript 可以被转换成任何一种并在浏览器中运行,所以它不是一个拦截器。

Not-native support非本地支持

What is the status of TypeScript support by the modern browsers ?现代浏览器对 TypeScript 的支持情况如何?

Typescript compiles to JS so it's supported by all browsers (even IE6) Typescript 编译为 JS,因此所有浏览器(甚至 IE6)都支持它

What are the positions of the major browser vendors for the future support of TypeScript ?各大浏览器厂商对于 TypeScript 未来的支持是什么立场?

No work is needed on behalf of browser vendors.无需代表浏览器供应商开展工作。

What is the relation between TypeScript and ECMAScript6 and does TypeScript provide much more features than ECMAScript6 ? TypeScript 和 ECMAScript6 之间有什么关系,TypeScript 提供的功能是否比 ECMAScript6 多得多?

Yes eg from future javascript versions eg class fields and static properties in classes.是的,例如来自未来的 javascript 版本,例如类中的类字段和静态属性。

Trying to design a web browser that could natively support more than one language at a time is exactly what Google tried to do with Dart.尝试设计一种可以同时支持多种语言的 Web 浏览器正是 Google 尝试使用 Dart 做的事情。 There was a Dart engine planned for Chrome but this ended up being too big a task with very little benefit aside from "just not using java script".有一个为 Chrome 计划的 Dart 引擎,但这最终是一项太大的任务,除了“只是不使用 java 脚本”之外几乎没有什么好处。

I suspect supporting Typescript natively would be an equally daunting task.我怀疑原生支持 Typescript 将是一项同样艰巨的任务。 Probably better to just improve upon ECMAScript and add in a few TS ideas where they make sense.可能更好的是改进 ECMAScript 并在有意义的地方添加一些 TS 想法。 I do love TS though.不过我确实喜欢TS。

Typescript cannot be run or understood in any browser.无法在任何浏览器中运行或理解打字稿。 So, Typescript is compiled to Javascript (which browsers can understand).因此,Typescript 被编译为 Javascript(浏览器可以理解)。 Typescript can use all ES6 features and during the compilation they will be converted to Target compile options like ES5. Typescript 可以使用所有 ES6 特性,并且在编译过程中它们将被转换为像 ES5 这样的 Target 编译选项。

Currently it won't work, it's an interesting topic though.目前它不起作用,但这是一个有趣的话题。 Would be good to know if at some point ECMAScript is going to support interfaces, types and other things.最好知道 ECMAScript 是否会在某个时候支持接口、类型和其他东西。 Especially, what I can notice that ES actually takes slowly some parts from the TypeScript, eg enums.特别是,我注意到 ES 实际上从 TypeScript 中缓慢地提取了一些部分,例如枚举。

If it would work I'd rather see it as ECMAScript taking from TypeScript some stuff rather than natively supporting TypeScript itself.如果它行得通,我宁愿将其视为 ECMAScript 从 TypeScript 中获取一些东西,而不是本机支持 TypeScript 本身。

I know it's currently not supported and there are no plans to support TypeScript natively in the browser but there is a huge (in my opinion) problem with tooling in the frontend (JavaScript) ecosystem - there's too much of it.我知道它目前不受支持,也没有计划在浏览器中原生支持 TypeScript,但在我看来,前端 (JavaScript) 生态系统中的工具存在一个巨大的问题——太多了。 Bundling, module resolution, transpiling , and more.捆绑、模块解析、转译等。

I think it makes development much slower, because there are a lot of issues with configurations, versions mismatch, compatibility and a lot of obscure issues (Stack Overflow and GitHub are full of such topics) that stem from the tooling, not implementing features.我认为这会使开发速度变慢,因为有很多配置问题、版本不匹配、兼容性和许多模糊问题(Stack Overflow 和 GitHub 充满了此类主题)源于工具,而不是实现功能。

I would call it a crisis, but it has been like this for a while and I know this is the way of doing things now.我会称之为危机,但这种情况已经有一段时间了,我知道这就是现在的做事方式。

I think there are a few things that need to happen.我认为有几件事需要发生。

  1. We need to be able to use native ES6 modules (import/export) in the browser.我们需要能够在浏览器中使用原生ES6模块(导入/导出)。 I know it's supported, but only a relative or URL imports work.我知道它受支持,但只有亲戚或 URL 导入工作。 I know there is work on "import maps" or whatever they are called.我知道有关于“导入地图”或任何名称的工作。

  2. It would be great if browsers (Chrome) can read TypeScript code.如果浏览器(Chrome)可以读取 TypeScript 代码,那就太好了。 It doesn't have to interpret or enforce any typing - essentially treat it like JavaScript with some additional nonsense that the browser just ignores.它不必解释或强制执行任何键入 - 本质上将其视为 JavaScript 以及浏览器忽略的一些额外废话。 It could be just a "developer mode" in the browser but we would be able to achieve 0-transpiling during development.它可能只是浏览器中的“开发者模式”,但我们将能够在开发过程中实现 0-transpiling。

  3. Simplify eager resource loading (to avoid bundling)简化急切的资源加载(以避免捆绑)

Again, this is just for development benefit.同样,这只是为了开发利益。 I know a lot of these tools have their place in production builds, older browser support, etc.我知道很多这些工具在生产构建、旧浏览器支持等方面都有自己的位置。

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

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