Skip to content

instantiate from loader gives a type error #1192

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

Closed
9oelM opened this issue Mar 26, 2020 · 0 comments · Fixed by #1193
Closed

instantiate from loader gives a type error #1192

9oelM opened this issue Mar 26, 2020 · 0 comments · Fixed by #1193

Comments

@9oelM
Copy link

9oelM commented Mar 26, 2020

I tried to instantiate with asc loader, lilke this:

instantiate<{}>(wasm, {
  env: {
    abort: (msg: number, file: number, line: number, column: number) => {
      console.error("abort called at" + file + " " + line + ":" + column);
    }
  },
})

And It gives a following error:

error TS2411: Property 'env' of type '{ memory?: Memory | undefined; table?: Table | undefined; seed?: (() => number) | undefined; abort?(msg: number, file: number, line: number, column: number): void; trace?(msg: number, numArgs?: number | undefined, ...args: number[]): void; } | undefined' is not assignable to string index type 'Record<string, ImportValue>'.

I'm using assemblyscript@0.9.4-nightly.20200325.

The error was gone when I tried this:

export interface WasmEnv {
  env?: {
    memory?: WebAssembly.Memory,
    table?: WebAssembly.Table,
    seed?: () => number,
    abort?(msg: number, file: number, line: number, column: number): void,
    trace?(msg: number, numArgs?: number, ...args: number[]): void
  };
}

/** WebAssembly imports with two levels of nesting. */
export type Imports = WasmEnv & Record<string, Record<string, ImportValue>>;

instead of the existing type:

/** WebAssembly imports with two levels of nesting. */
export interface Imports extends Record<string, Record<string, ImportValue>> {
  env?: {
    memory?: WebAssembly.Memory,
    table?: WebAssembly.Table,
    seed?: () => number,
    abort?(msg: number, file: number, line: number, column: number): void,
    trace?(msg: number, numArgs?: number, ...args: number[]): void
  };
}

Yeah, so maybe the type definitions of the loader needs to be fixed.

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

Successfully merging a pull request may close this issue.

2 participants