fix(no-base-to-string): handle overloaded toString declarations#779
Conversation
How to use the Graphite Merge QueueAdd the label 0-merge to this PR to add it to the merge queue. You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Pull request overview
This PR fixes the no-base-to-string lint rule to correctly handle types with overloaded toString (or toLocaleString/valueOf) declarations, preventing both false positives (flagging types that have a user-defined overloaded toString) and false negatives (not flagging synthesized mapped-type properties with zero declarations).
Changes:
- Replaced the single-pass
toString/toLocaleStringcheck (which incorrectly returnedusefulnessAlwaysfor any symbol with a declaration count ≠ 1) with a loop over["toString", "toLocaleString", "valueOf"]that correctly distinguishes user-defined declarations from Object-only declarations. - Added two new valid test cases (overloaded class
toStringand overloaded ambient module functiontoString) and one new invalid test case (synthesized mapped-typetoStringwith no declarations). - Updated the test snapshot to include the new diagnostic for the mapped-type test case.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
internal/rules/no_base_to_string/no_base_to_string.go |
Core logic rewrite: iterates over toString, toLocaleString, and valueOf; skips synthesized (zero-declaration) properties; uses utils.Some to detect any non-Object declaration |
internal/rules/no_base_to_string/no_base_to_string_test.go |
New valid cases for overloaded toString; new invalid case for mapped type with zero declarations |
internal/rule_tester/__snapshots__/no-base-to-string.snap |
Snapshot updated to include the new invalid-87 diagnostic |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
Merge activity
|
71f2de7 to
b4f666b
Compare

Upstream reference: typescript-eslint/typescript-eslint@2029c78
Context: typescript-eslint/typescript-eslint#12089