I currently have a TypeScript project and am in the process of incorporating a WebAssembly Module to replace certain functionalities.
Successfully importing the WebAssembly module involved moving the .wasm loading logic to its own .js file, which is then imported as a TypeScript module into the file where I intend to use the WebAssembly functions.
As an example, I created a basic add function in WebAssembly:
In the .ts that compiles to .wasm using AssemblyScript:
export function add(a: i32, b: i32): i32 {
return a + b;
}
In the .js file:
export async function loadWasm() {
const imports = {}; // Omitted for simplicity
const module = await
WebAssembly.instantiateStreaming(fetch('path/to/file.wasm'),imports);
return module;
}
And in the .ts file where I want to utilize the WebAssembly:
loadWasm().then((module: any) => {
let addFunc: ((a: number, b: number) => any) = module.add;
console.log('Adding 2 and 5 in Wasm: ' + addFunc(2, 5));
});
However, upon execution, I encounter the following error:
Uncaught (in promise) TypeError: addFunc is not a function at eval
Would appreciate any insights on what could be causing this issue.