website icon indicating copy to clipboard operation
website copied to clipboard

Adding JavaScript/TypeScript to AssemblyScript migration guide

Open aminya opened this issue 5 years ago • 2 comments

It would be nice to have a guide for converting an already written JavaScript/TypeScript codebase to AssemblyScript. AssemblyScript can shine in this regard due to its similar syntax.

Things to cover:

  1. Setting up the project:
    • Setting up your Directories
    • Writing build scripts (asc)
    • Setting up the loaders (mostly as-bind loader)

For these asinit can probably help when starting a new project, but when you want to migrate the story is a little different.

  1. Source code
    • How to add types

      • convert number to (i32, f32, etc).
      • convert Arrays (like number[]) to typed arrays (Float32Array, etc) and static arrays (StaticArray)
      • a simple guide about the allowed class sytnax.
    • How to separate or arrange JavaScript calls

      • DOM API
      • other JavaScript functions

Note: I would like this guide to include as-bind, which is a better loader for the start. Even in Rust, there is no need to meticulously allocate and release Arrays, Strings, etc. If someone needed more flexibility and something was not covered by as-bind they can switch to the original loader.

In my opinion, the current AssemblyScript book is more like a reference, and having a practical guide is very necessary.

As a reference, there is this JavaScript => TypeScript migration guide here: https://www.staging-typescript.org/docs/handbook/migrating-from-javascript.html

aminya avatar Aug 03 '20 21:08 aminya

A "converting from TS to AS" kind of guide can become quite complex when getting into the details. It can be easy if the existing code base permits (code cleverly optimized to never dopt), or be a complete bummer if the existing code base is essentially JS with supposedly clever typing (but functionally worthless). Hesitating a bit because I don't yet have a good idea how to convey this in a way that the sheer existence of the guide doesn't induce hope just to shatter it again.

dcodeIO avatar Aug 17 '20 10:08 dcodeIO

We could generate these type annotations if we had a run-time type-checking tool like Python's MonkeyType, but I've never seen a similar tool for JavaScript.

jarble avatar May 10 '24 18:05 jarble