2

I saw that there already is a compiler for compiling TypeScript to WebAssembly (Wasm), here is the link.

I also heard from multiple sources that compiling JS to Wasm wouldn't be feasible, because of JavaScript's dynamic nature and dynamic types.

However, TypeScript does offer typed variables which JavaScript lacks. And in the future Wasm might be able to even interact with the DOM/interact with other web API.

Question:

Would writing applications in TypeScript and compiling it to Wasm offer any performance benefits when compared to writing a web application in JavaScript?

1
  • 2
    I think you should replace TypeScript with AssemblyScript to avoid confusion. Commented Aug 19, 2018 at 14:17

2 Answers 2

4

The realistic answer is: no. There are a few common misunderstandings about TypeScript. One is that it is less dynamic than JavaScript. That is not true, it is in fact every bit as dynamic as JS, because it encompasses all of JavaScript's semantics (including all the crazy corner cases) and its type system is far too weak and unsound to provide guarantees that an ordinary offline compiler could use for static optimisations. At best, the types can be used as hints that a dynamic VM could try to optimise for first, well knowing that they might turn out to be incorrect.

(Also, I'm not aware of a TypeScript-to-Wasm compiler. You're probably thinking of AssemblyScript, but while that reuses TypeScript's syntax, its semantics is very different.)

1
0

You referenced AssemblyScript in your question. Assembly script is an extremely strict subset of typescript. Don't confuse it with typescript it's self. The big difference being that Typescript encompasses all of the dynamic attributes that we all know and love (hate) in Javascript. AssemblyScript on the other hand does not.

Examples of a couple of the big differences are; in AssemblyScript you can not have closures. You also can not have union types.

1

Not the answer you're looking for? Browse other questions tagged or ask your own question.