Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript support in modern browsers

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:

  1. What is the status of native TypeScript support by the modern browsers?

  2. What are the positions of the major browser vendors for the future support of TypeScript natively?

  3. What is the relation between TypeScript and ECMAScript 6 and does TypeScript provide much more features than ECMAScript 6?

like image 683
Artem Kharytoniuk Avatar asked Apr 05 '14 19:04

Artem Kharytoniuk


People also ask

Does TypeScript work in Chrome?

You cannot use Typescript in Chrome. Typescript is superset of JS and you must first compile .

Can TypeScript directly run on browser?

To run TypeScript in a browser, it needs to be transpiled into JavaScript with the TypeScript compiler (tsc). In this case, tsc creates a new . js file based on the . ts code, which you can use any way you could use a JavaScript file.

Do modern browsers support JavaScript?

All the modern browsers come with built-in support for JavaScript. Frequently, you may need to enable or disable this support manually. This chapter explains the procedure of enabling and disabling JavaScript support in your browsers: Internet Explorer, Firefox, chrome, and Opera.

What browsers work with JavaScript?

Activate JavaScript in another browserMicrosoft Edge. Mozilla Firefox. Apple Safari.


4 Answers

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 6 MB of supporting JavaScript 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 JavaScript, so it's supported by all browsers (even Internet Explorer 6).

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.

like image 186
basarat Avatar answered Oct 12 '22 22:10

basarat


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

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

like image 34
matthew Avatar answered Oct 12 '22 20:10

matthew


TypeScript cannot be run or understood in any browser. So, TypeScript is compiled to JavaScript (which browsers can understand). TypeScript can use all ECMAScript 2015 features and during the compilation they will be converted to target compile options like ES5.

like image 42
nithish peddi Avatar answered Oct 12 '22 20:10

nithish peddi


Currently it won't work, but it's an interesting topic though. It would be good to know if at some point ECMAScript is going to support interfaces, types and other things. Especially, I can notice that ECMAScript actually slowly takes some parts from the TypeScript, e.g. enums.

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

like image 32
Daniel Danielecki Avatar answered Oct 12 '22 22:10

Daniel Danielecki