Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

315
Vistas
How to export classes from AssemblyScript?

I am trying to port my simple collision detection library from JavaScript to WebAssembly for speed. After looking up languages that compile to WASM, AssemblyScript seemed to be perfect as I only needed to add types to my JS file. The whole library is a Class and after adding types I tried to compile it but it does not compile properly. For example, compiling this using command npx asc path/to/main.ts -o wasm.wasm --exportRuntime -t wasm.wat --bindings esm:

export class Test {
    constructor() {
        console.log('Successful!');
    }
};

Resulted in this error:

WARNING AS235: Only variables, functions and enums become WebAssembly module exports.

 export class Test {
              ~~~~
 in main.ts(1,14)

After seeing the error I tried to fix it by doing:

class Test {
    constructor() {
        console.log('Successful!');
    }
};

export function getTest(): Test {
    return Test;
};

But that resulted in another error:

ERROR AS234: Expression does not compile to a value at runtime.

     return Test;
            ~~~~
 in main.ts(8,12)

FAILURE 1 compile error(s)

So I tried to do this:

class Test {
    constructor() {
        console.log('Successful!');
    }
};

export function getTest(): Test {
    return new Test();
};

That compiled successfully and after calling getTest from JavaScript I got an output Successful! in the console but it did not return the initiated class, instead I got this: [Number (Internref): 18624].

So I serched on the internet for solution and found this. But the accepted solution there is to use AssemblyScript Loader, which is deprecated. I also know about as-bind but it states that it wraps around AssemblyScript Loader so, indirectly, it is also deprecated. So how can I export classes from AssemblyScript?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

So, there currently is no way to export classes. However, you can call methods on a class from JavaScript or call a get or set method to modify data. Idk if I can answer further, but I would recommend checking in with dcode at the AssemblyScript Discord.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda