Repository navigation
fix: do not split type unions inside parentheses - #208
Conversation
safelySeparateTypeStringOn tracked nesting depth for <> and {} but not
(), so a parenthesized union such as the true branch of
`string extends T ? (A | B) : C` was split at the top level and the
resulting fragments were re-emitted as a broken union.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HmVsAQiHawruFHijTtkzV9
There was a problem hiding this comment.
Looks good, straightforward and well-tested fix.
- Reviewed the depth-tracking change in
safelySeparateTypeStringOn(src/markdown-helpers.ts) that adds(/)to the existing</>/{/}nesting counter. - Checked the new unit tests covering parenthesized unions inside conditional types, non-splitting of
|/,inside parens, and correct splitting of top-level unions adjacent to parenthesized groups. - Considered whether an unmatched
)could drive depth negative and permanently suppress splitting — this is a pre-existing property of the same counter (already true for stray>/}) and unlikely given typical balanced TS type strings.
Extended reasoning...
The change is a small, mechanical two-line addition to an existing depth-counter switch statement in src/markdown-helpers.ts, extending the same pattern already used for angle brackets and braces to parentheses, with corresponding unit tests added in tests/markdown-helpers.spec.ts. It touches no security-sensitive surface (no auth, crypto, injection, or data exposure — purely a docs/type-string parsing helper). A human reviewer (jkleinsc) already approved it, CODEOWNERS only lists a broad working group with no conflict, and the one theoretical concern (negative depth from an unmatched paren permanently disabling splitting) is a pre-existing property of the same mechanism for the other bracket types and was already weighed as unlikely given typical balanced TypeScript type strings.
|
🎉 This PR is included in version 3.0.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Requested by John Kleinschmidt · Slack thread
The type-string splitter tracks nesting depth for angle brackets and braces but not parentheses, so a parenthesized union is split at the top level. This matters for a conditional return type such as
string extends T ? (A | B) : C, which Electron wants to use soclipboardItem.getType()returns a narrowed type based on its MIME argument. This change counts parentheses as nesting too and adds unit tests for the conditional case and for top-level unions next to parenthesized groups. Regeneratingelectron.d.tsfrom current Electronmaindocs with this change produces byte-identical output, so existing docs are unaffected.🤖 Generated with Claude Code
https://claude.ai/code/session_01HmVsAQiHawruFHijTtkzV9
Generated by Claude Code