fix: detect and error on TS type name collisions during export#483
Open
jcrugzz wants to merge 1 commit intoAleph-Alpha:mainfrom
Open
fix: detect and error on TS type name collisions during export#483jcrugzz wants to merge 1 commit intoAleph-Alpha:mainfrom
jcrugzz wants to merge 1 commit intoAleph-Alpha:mainfrom
Conversation
When two different Rust types derive TS with the same TypeScript name, they write to the same output file. Previously this was silent last-writer-wins. Now `export_and_merge` compares file content and returns an actionable `ExportError::Collision` when the generated output differs, while still allowing idempotent re-exports. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
jcrugzz
added a commit
to jcrugzz/ts-rs
that referenced
this pull request
Mar 5, 2026
When TS_RS_AUTO_NAMESPACE=true (or Config::with_auto_namespace(true)),
all exported types are organized into {crate_name}/ subdirectories.
This prevents collisions entirely — different crates get different
directories with correct relative import paths between them.
Follow-up to Aleph-Alpha#483 which added collision detection.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This was referenced Mar 5, 2026
jcrugzz
added a commit
to jcrugzz/ts-rs
that referenced
this pull request
Mar 5, 2026
When TS_RS_AUTO_NAMESPACE=true (or Config::with_auto_namespace(true)),
all exported types are organized into {crate_name}/ subdirectories.
This prevents collisions entirely — different crates get different
directories with correct relative import paths between them.
Follow-up to Aleph-Alpha#483 which added collision detection.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
4dawit
pushed a commit
to 4dawit/ts-rs
that referenced
this pull request
Mar 5, 2026
* fix: detect and error on TS type name collisions during export
When two different Rust types derive TS with the same TypeScript name,
they write to the same output file. Previously this was silent
last-writer-wins. Now `export_and_merge` compares file content and
returns an actionable `ExportError::Collision` when the generated
output differs, while still allowing idempotent re-exports.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* feat: add opt-in auto-namespace by crate name to avoid type collisions
When TS_RS_AUTO_NAMESPACE=true (or Config::with_auto_namespace(true)),
all exported types are organized into {crate_name}/ subdirectories.
This prevents collisions entirely — different crates get different
directories with correct relative import paths between them.
Follow-up to Aleph-Alpha#483 which added collision detection.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
#[derive(TS)]with the same TypeScript name (e.g. via#[ts(rename = "...")]), they write to the same output file. The current behavior atexport_and_mergeline 165-167 is silent last-writer-wins — the second type is silently dropped withreturn Ok(()), producing nondeterministic TypeScript output.ExportError::Collisionwith an actionable error message suggesting#[ts(rename = "...")]or#[ts(export_to = "...")]to disambiguate.idempotent_export(same type twice succeeds) andcollision_is_detected(different types with same TS name errors).What stays the same
export_to) — untouchedEXPORT_PATHSstatic type signature — unchangedTest plan
cargo test --all-features --test integration collision— new tests passcargo test --no-default-features --test integration collision— passes without serde-compatcargo test --all-features --test integration same_file_export— existing regression guard passescargo test --all-features— full suite (528+ tests) passes with zero failures🤖 Generated with Claude Code