Skip to content

Include corresponding values in d.ts for C-style enums #2730

Closed
@remagpie

Description

@remagpie

Motivation

wasm_bindgen macro supports C-style enums. It supports specifying literal values for each enum variant, but it seems that those values are not included in the generated d.ts file. For example,

#[wasm_bindgen]
pub enum ErrorCode {
    FooError = 0,
    BarError = 2,
}

is converted to the following code:

export enum ErrorCode {
  FooError,
  BarError,
}

Specifying the actual values of enum lets us use more features in typescript, so it would be nice if the corresponding literal values are included in d.ts.

Proposed Solution

The ideal solution would give us the following typescript code:

export enum ErrorCode {
  FooError = 0,
  BarError = 2,
}

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