emscripten-core / emscripten-core/emscripten

TypeScript declarations should generate `MainModule` type name based on user inputs

Open
#21,470 5 comments 0 reactions 1 assignee Claimed by @brendandahl View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

Currently, users generating TypeScript declarations as part of compilation always get a file where the wasm module's main type is named `MainModule`. One consequence of this is that users generating packages directly from the TSD and wasm/js output wind up with name collisions, if they import multiple modules into another project. Working around this is not difficult (shown below) but it does betray the fact that, at the time of writing, wasm module type names are hard-coded to be `MainModule`.

```ts
import { MainModule as MyModule1 } from "my-package-1"; // Must use "as" to prevent name collision
import { MainModule as MyModule2 } from "my-package-2";
```

Further, users can specify names using `-s EXPORT_NAME=MyModule` (though this isn't always 1:1 with what we'd want to call the module's type), so having an output type name of `MainModule` can be confusing to users.

Per [a conversation](https://github.com/emscripten-core/emscripten/pull/21460#discussion_r1509484936) in #21460, and #20296, align TSD generation with `EXPORT_NAME` or a new setting e.g. `MODULE_NAME`, so that users can set this name automatically.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.