Closed
Description
Taking the quickstart example and adding tsdFile
entries such as
{
"targets": {
"release": {
"binaryFile": "build/optimized.wasm",
"textFile": "build/optimized.wat",
"sourceMap": true,
"optimize": true,
"tsdFile":"build/optimized.d.ts"
}
},
"options": {}
}
generates optimized.d.ts
declare module ASModule {
type i8 = number;
type i16 = number;
type i32 = number;
type i64 = BigInt;
type isize = number;
type u8 = number;
type u16 = number;
type u32 = number;
type u64 = BigInt;
type usize = number;
type f32 = number;
type f64 = number;
type bool = any;
export function __alloc(size: usize, id: u32): usize;
export function __retain(ptr: usize): usize;
export function __release(ptr: usize): void;
export function __collect(): void;
export var __rtti_base: usize;
export function add(a: i32, b: i32): i32;
}
export default ASModule;
However when you load the wasm via const wasmModule = loader.instantiateSync(fs.readFileSync(__dirname + "/build/optimized.wasm"), imports);
its not picking up the wasm as a module. However is you take the .d.ts contents and modify to be
type i8 = number;
type i16 = number;
type i32 = number;
type i64 = BigInt;
type isize = number;
type u8 = number;
type u16 = number;
type u32 = number;
type u64 = BigInt;
type usize = number;
type f32 = number;
type f64 = number;
type bool = any;
export interface QuickStart {
add: (a: i32, b: i32) => i32;
}
and load via const myModule: QuickStart = require("..");
. It autocompletes properly.
What's the correct way to use the module declarations or can it be converted to an interface declaration?