Skip to content

Unnecessary Typescript definitions are created for web_sys string enums #4163

Closed
@davids-work

Description

@davids-work

Describe the Bug

After updating to wasm_bindgen 0.2.94 / web_sys 0.3.71, I noticed that the generated Typescript definition file created by wasm-pack contained definitions for a bunch of string enums stemming from web_sys, e.g.

/**
 *The `MediaSourceReadyState` enum.
 *
 **This API requires the following crate features to be activated: `MediaSourceReadyState`*
 */
export type MediaSourceReadyState = "closed" | "open" | "ended";

These were not there with wasm_bindgen 0.2.93.

Steps to Reproduce

Cargo.toml:

[package]
name = "wasm-bindgen-unnecessary-bindings"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib"]

[dependencies]
wasm-bindgen = { version = "0.2.94" }

[dependencies.web-sys]
version = "0.3.71"
features = [
    "console",
    "MediaSourceReadyState",
]

src/lib.rs

use wasm_bindgen::prelude::wasm_bindgen;
use web_sys::{console::info, js_sys::Array};

// Note how MediaSourceReadyState is not used anywhere!

#[wasm_bindgen]
pub fn foo() {
    // Just to create some reference to web_sys so that it's actually pulled in
    info(&Array::new());
}

Build: wasm-pack build --release --target web

Expected Behavior

Definitions are only generated for types that are part of my crate's interface

Actual Behavior

Definitions are generated for the web_sys::MediaSourceReadyState enum despite it not being part of my library at all.

More string enum definitions are generated if other web_sys features are enabled

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions