[Web API type definition issue] WebAssembly.Module interface is empty, allowing invalid assignments

Open
#2,172 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
typescript, wasm
Domain
tooling, web-dev

Research direction

Start with the WebAssembly.Module declaration shown in the issue and reproduce the assignment in the linked TypeScript Playground. Determine how the generated interface can distinguish Module instances from arbitrary values while matching the supported Web API, then verify that the assignment is rejected without breaking valid Module usage.

Written by the indexing model from the issue text.

Description

lib.d.ts bug
Summary

The WebAssembly.Module interface is currently emitted as an empty interface, making it structurally compatible with any object in TypeScript

Expected vs. Actual Behavior
const abc: WebAssembly.Module = 0;

I would expect the above to be a compilation error.

But WebAssembly.Module gets emitted as an empty interface allowing all assignments.

interface Module { }
Playground Link

https://www.typescriptlang.org/play/?#code/MYewdgzgLgBAhgI2ALhgdQKYIIIQhgWwQBsBPAOgFkQATAV2IxgF4YAGAbiA

Browser Support
  • This API is supported in at least two major browser engines (not two Chromium-based browsers).
Have Tried The Latest Releases
  • This issue applies to the latest release of TypeScript.
  • This issue applies to the latest release of @types/web.
Additional Context

Do we need to make WebAssembly.Module nominally typed? 🫣

I'm not aware of any other interfaces with only constructors/static methods but no instance members

Dominant language
TypeScript
Stars
740
Forks
474
Avg merge
2d 8h
Merged PRs (30d)
15

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/TypeScript-DOM-lib-generator

All issues in microsoft/TypeScript-DOM-lib-generator

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.