Skip to content

refactor: unify type discovery and improve Rust type parsing#39

Open
ap-apely wants to merge 3 commits into
thwbh:developfrom
ap-apely:event-dirpath-fix
Open

refactor: unify type discovery and improve Rust type parsing#39
ap-apely wants to merge 3 commits into
thwbh:developfrom
ap-apely:event-dirpath-fix

Conversation

@ap-apely
Copy link
Copy Markdown

  • Added support for snake_case keys in tauri.conf.json (e.g. project_path)
  • Fixed enum type discovery (recursive parsing of tuple and struct variants)
  • Improved Rust type parsing:
  • module-qualified types (std::collections::HashMap)
  • slices ([u8])
  • fixed arrays ([u8; 32])
  • Stripped lifetimes (e.g. 'a) from generic arguments to avoid unknown types in TypeScript
  • Deduplicated events by name
  • Fixed path filtering for .git and target using path components instead of string matching
  • Unified type discovery logic and removed duplicate traversal in generators
  • Added support for projects where src-tauri is the root directory

Previously, some valid Rust types were not parsed correctly.

For example:

#[derive(serde::Serialize)]
pub struct Example<'a> {
    pub data: &'a std::collections::HashMap<u64, Permissions>,
    pub bytes: &'a [u8],
}

Issues:

  • lifetimes ('a) caused unknown types in TypeScript
  • module-qualified types (std::collections::HashMap) were not resolved
  • slices ([u8]) were not supported

Another case:

#[derive(serde::Serialize)]
#[serde(tag = "type", content = "data")]
pub enum Event<'a> {
    Message(&'a str),
}

Issues:

  • enum variant types were not discovered recursively
  • generated types were incomplete or missing

These cases are now handled correctly.

… are applied. Added support for `snake_case` keys in `tauri.conf.json` so `project_path` actually works.

*   **Enum Type Discovery**: Fixed the analyzer to recursively find and generate types used inside enum variants (tuple and struct styles).
*   **Rust Type Parsing**: Added support for module-qualified names (`std::collections::HashMap`), slices (`[u8]`), and fixed arrays (`[u8; 32]`).
*   **Lifetime Filtering**: Updated the parser to strip out lifetimes like `'a` from generic arguments, preventing `unknown` types in TypeScript.
*   **Event Deduplication**: Generators now deduplicate events by name so you don't get multiple listeners for the same event string.
*   **Path Handling**: Switched skip-logic for `target` and `.git` folders to use proper path components instead of string matching.
*   **Cleaned Up Generators**: Centralized all type discovery logic into a single method, removing redundant manual loops from both TS and Zod generators.
@thwbh
Copy link
Copy Markdown
Owner

thwbh commented Apr 2, 2026

Hi @ap-apely thank you for the contribution! Would you please create an issue, too, describing the problem your change fixes?
https://github.com/thwbh/tauri-typegen/issues

After that, I'll pick it up for the next version.

@thwbh thwbh linked an issue Apr 13, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resolve Rust idiomatic keywords

2 participants