Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding JavaScript/TypeScript to AssemblyScript migration guide #11

Open
aminya opened this issue Aug 3, 2020 · 2 comments
Open

Adding JavaScript/TypeScript to AssemblyScript migration guide #11

aminya opened this issue Aug 3, 2020 · 2 comments

Comments

@aminya
Copy link
Contributor

aminya commented Aug 3, 2020

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

@dcodeIO
Copy link
Member

dcodeIO commented Aug 17, 2020

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.

@jarble
Copy link

jarble commented May 10, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants