ColinEberhardt / wasmweekly

Website for the WebAssembly weekly newsletter
http://wasmweekly.news/
Creative Commons Zero v1.0 Universal
74 stars 11 forks source link

TypeScript is JavaScript #83

Closed loxcel closed 1 year ago

loxcel commented 1 year ago

Colin,

Enjoy your WebAssembly updates.

From https://wasmweekly.news/issue-178:

AssemblyScript is a TypeScript-like language : JavaScript ... isn’t a natural fit for compiling to WebAssembly

Because TypeScript is JavaScript, we can also infer

TypeScript ... isn’t a natural fit for compiling to WebAssembly

This inference is correct, so why is AssemblyScript based on a language that "isn't a natural fit?"

It isn't.

AssemblyScript claims to be a "subset of TypeScript" or "a TypeScript-like language." But that's a stretch, like a claim that English is a subset of TypeScript because, like TypeScript, English uses letters too. Perhaps this claim attempts to ride the TypeScript popularity wave (like JavaScript did with Java 20 years earlier). AssemblyScript lacks TypeScript's complex type mechanisms, which makes Typescript "TypeScript", and JavaScript and TypeScript's dynamic behavior and many other oddities.

You cannot take a typical TypeScript application -- or even a subset -- and expect AssemblyScript to compile it.

In summary, AssemblyScript borrows TypeScript syntax, but little else.

ColinEberhardt commented 1 year ago

That's a fair challenge - AssemblyScript adds static typing to JavaScript, just like TypeScript does, however, that is where the similarities end. To your point, the TypeScript type-system is way more powerful.

Interesting.

MaxGraey commented 1 year ago

Not every TS code can be compiled into Wasm via AS, but absolutely every AS code can be compiled into JS via tsc (the asc compiler itself is a good example, it compiles into JS and Wasm). Therefore, strictly speaking, AssemblyScript is a subset of TypeScript, while TypeScript is a superset of JavaScript.

Similarly, not every JavaScript code can be compiled by tsc without changes (adding type annotations, sometimes even restructuring the program, ts-ignore, forcing coercion via val as unknown as ... and etc), especially if allowJS set to false and all strict modes in tsconfig are enabled.

Moreover, even JS itself has its own subset, which is enabled by the "use strict" directive. But that doesn't make non-strict ES3 + propotypes code more "JavaScripty" than ES6 with strict mode with classes right?

AssemblyScript inherits not only syntax but also runtime (and built-in objects) and in some part semantics. AS does not yet support union types, closures and some structural typings, but this is only because it is still developing and it is not easy to do so effectively.

MaxGraey commented 1 year ago

@loxcel You have a rather strange GitHub account. You've only created 2 issues in for all 5 years. All of them were addressed to AssemblyScript. Your first issue: https://github.com/ColinEberhardt/wasmweekly/issues/47

Heath123 commented 1 year ago

AssemblyScript calls itself a variant of TypeScript, so even though there is valid AssemblyScript that is not valid TypeScript (e.g. the low level memory operations(, since the syntax is heavily inspired by and mostly compatible with TypeScript this is still correct

You cannot take a typical TypeScript application -- or even a subset -- and expect AssemblyScript to compile it.

AssemblyScript being a subset would mean that you can compile AssemblyScript code with the TypeScript compiler (and you mostly can), not the other way around

CountBleck commented 1 year ago

AssemblyScript adds static typing to JavaScript

AssemblyScript isn't an extension of JavaScript. It's a language that compiles to WebAssembly. I think "AssemblyScript adds TS-like syntax and semantics to WebAssembly" would be a more accurate statement. I can't think of any other language targeting Wasm whose syntax and behavior is as familiar to JS/TS programmers, and that's the most valuable aspect of AssemblyScript in my opinion.

On that note, I think a comparison between AS and other Wasm languages is relevant.

dcodeIO commented 1 year ago

AssemblyScript is actually very transparent about what it is and what it isn't. It's one of the most transparent and honest efforts in the Wasm space - if not the most - which I assume motivates some people to never get tired to baselessly attack it.

From the AssemblyScript FAQ:

What are the differences between AssemblyScript and TypeScript?

TypeScript transpiles down to JavaScript, a dynamic just-in-time compiled language. AssemblyScript, on the other hand, compiles to a static WebAssembly binary. Their compiler implementations are quite different. However, the two languages are so very similar on the surface that they share many concepts. For example, TypeScript tooling can be used to author and refactor AssemblyScript code and, with some effort, the same code base can be transpiled to JavaScript with tsc and compiled to WebAssembly with asc, or code shared. The AssemblyScript compiler itself is portable.

From the introduction:

AssemblyScript compiles a variant of TypeScript (a typed superset of JavaScript) to WebAssembly.

The many similarities, reuse of TS tooling and cross-TS/AS portability options certainly justify a statement like the herein criticized "AssemblyScript is a TypeScript-like language". Stating that it is "like a claim that English is a subset of TypeScript because, like TypeScript, English uses letters too" is, frankly, the weakest contemplation I've seen in some time ;)

ColinEberhardt commented 1 year ago

I honestly don't think this debate is adding any value.

AssemblyScript is an important language in the WebAssembly ecosystem, and I am going to continue to call it TypeScript-like simply because I feel that is the best way to describe the language!