Skip to content

Unexpected call order when .d.ts and exports don't match #137

@thecodedrift

Description

@thecodedrift

Overview

Ran into this bug while adding new export to a wasm module written in the JS PDK. I forgot to update the .d.ts file and ended up with a very difficult to triage bug. It may be easier to just check the exports in the compiled JS against the .d.ts and throw an exception if they don't match.

Setup

// index.d.ts
declare module "main" {
  export function pre(): I32;
  export function post(): I32;
}
// index.ts
export function pre() {
  // noop
console.log("I am pre");
}

export function chunk() {
  // noop
  console.log("I am chunk");
}

export function post() {
  // noop
  console.log("I am post");
}

Reproduction

Compiled using esbuild per the PDK guide. Call the compiled wasm module's pre and post methods from within an application. I used the node.js SDK for consistency in platform.

Expected

Calling the pre and post from within extism bindings (node.js) should output their corresponding strings.

Actual

  1. Logs I am pre
  2. Logs I am chunk

I can't say for sure what's happening here because I'm not sure at what point the .d.ts and exports are matched, but it seems like the order of functions inside of the index.ts matters if the exports don't match the .d.ts file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions