Skip to content

test(p2-shim): exercise instantiation generic types - #2233

Merged
vados-cosmonic merged 2 commits into
bytecodealliance:mainfrom
eduardomourar:fix/preview2-shim-instantiation-types
Oct 11, 2026
Merged

vados-cosmonic merged 2 commits into
bytecodealliance:mainfrom
eduardomourar:fix/preview2-shim-instantiation-types

Conversation

@eduardomourar

@eduardomourar eduardomourar commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

@bytecodealliance/preview2-shim/instantiation has three related typing bugs that make the documented versioned-import workflow unusable:

  • WASIShimConfig, SandboxConfig, GetImportObjectArgs, WASIImportObject, and VersionedWASIImportObject were declared without export in types/instantiation.d.ts, so consumers can't name them (TS2459/TS2305).
  • getImportObject's version generic lived only on a dead duplicate class declaration in types/; the implementation that's actually emitted to dist/common/instantiation.d.ts had no generic at all, so passing asVersion and a type argument together failed (TS2558).
  • The ./instantiation export's types condition pointed at ./dist/common/*.d.ts, where * is a literal filename rather than a pattern — it only resolved by accidental fallback to the .js target.

Changes

  • Export the five types from types/instantiation.d.ts; drop the dead duplicate WASIShim class declaration there.
  • Move the generic onto the real getImportObject implementation in src/common/instantiation.ts, inferring V from asVersion instead of requiring it twice; re-export the public types so they survive into dist/.
  • Fix the ./instantiation types condition to point directly at dist/common/instantiation.d.ts.
  • Add a regression test (test/types.ts + test/fixtures/types/instantiation-generics/) that compiles the documented versioned-import snippet and fails with the original errors against the pre-fix code.

@vados-cosmonic

Copy link
Copy Markdown
Collaborator

Ah nice catch @eduardomourar thanks for submitting this, this should prevent this from happening again

Code looks good to me (outside of the fmt failure) but once you're done I'm happy to review and merge this!

@eduardomourar
eduardomourar force-pushed the fix/preview2-shim-instantiation-types branch from fa89755 to dd1fe4c Compare October 9, 2026 09:42
@eduardomourar
eduardomourar marked this pull request as ready for review October 9, 2026 09:42
@vados-cosmonic
vados-cosmonic added this pull request to the merge queue Oct 11, 2026
Merged via the queue into bytecodealliance:main with commit e1418db Oct 11, 2026
65 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants