Skip to content

Feature request: support exporting Rust constants to TypeScript #441

@Choochmeque

Description

@Choochmeque

Is your feature request related to a problem? Please describe.
Currently, ts-rs can export structs and enums, but not constants.
This leads to duplicated definitions between Rust and TypeScript for shared values (like filenames, setting keys, limits, etc.), which can easily get out of sync.

Describe the solution you'd like
Allow ts-rs to export pub const values to TypeScript.
Example:

pub const SETTINGS_FILE: &str = "settings.json";

to

export const SETTINGS_FILE = "settings.json";

This could also work for numeric and boolean constants:

pub const MAX_ITEMS: u32 = 100;
pub const DEBUG_MODE: bool = true;

to

export const MAX_ITEMS = 100;
export const DEBUG_MODE = true;

Describe alternatives you've considered

  • Manually duplicating constants in Rust and TypeScript.
  • Custom build scripts to generate TS files separately.

Additional context
This would improve type safety and maintainability for shared front/back-end projects (e.g., Tauri apps).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions