Skip to content

fix: do not split type unions inside parentheses - #208

Merged
MarshallOfSound merged 1 commit into
mainfrom
fix/parenthesized-type-unions
Sep 24, 2026
Merged

MarshallOfSound merged 1 commit into
mainfrom
fix/parenthesized-type-unions

Conversation

@claude

@claude claude Bot commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

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 so clipboardItem.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. Regenerating electron.d.ts from current Electron main docs 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

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
@claude
claude Bot marked this pull request as ready for review September 24, 2026 16:53
@claude
claude Bot requested a review from a team as a code owner September 24, 2026 16:53

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@MarshallOfSound
MarshallOfSound merged commit 4551177 into main Sep 24, 2026
10 checks passed
@MarshallOfSound
MarshallOfSound deleted the fix/parenthesized-type-unions branch September 24, 2026 17:49
@electron-npm-package-publisher

Copy link
Copy Markdown

🎉 This PR is included in version 3.0.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants