TypeScript support in modern browsers

前端 未结 4 752
[愿得一人]
[愿得一人] 2020-12-29 19:25

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:<

相关标签:
4条回答
  • 2020-12-29 19:43

    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. Especially, what I can notice that ES actually takes slowly some parts from the TypeScript, e.g. enums.

    If it would work I'd rather see it as ECMAScript taking from TypeScript some stuff rather than natively supporting TypeScript itself.

    0 讨论(0)
  • 2020-12-29 19:46

    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. 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".

    I suspect supporting Typescript natively would be an equally daunting task. Probably better to just improve upon ECMAScript and add in a few TS ideas where they make sense. I do love TS though.

    0 讨论(0)
  • 2020-12-29 19:53

    Typescript cannot be run or understood in any browser. So, Typescript is compiled to Javascript (which browsers can understand). Typescript can use all ES6 features and during the compilation they will be converted to Target compile options like ES5.

    0 讨论(0)
  • 2020-12-29 19:56

    Native support

    Native support can be added quite easily e.g. https://github.com/basarat/typescript-script adds support for script tags (although this adds 6MB of supporting JS to a page). 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.

    Browser vendors have no plans to add native TypeScript support. The only native languages common across browsers are JavaScript and WebAssembly. TypeScript can be transpiled to either and run in the browsers so its not a blocker.

    Not-native support

    What is the status of TypeScript support by the modern browsers ?

    Typescript compiles to JS so it's supported by all browsers (even IE6)

    What are the positions of the major browser vendors for the future support of 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 ?

    Yes e.g. from future javascript versions e.g. class fields and static properties in classes.

    0 讨论(0)
提交回复
热议问题