fix(types): preserve define helper properties - #855
Conversation
|
Warning Review limit reached
Next review available in: 4 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesTyped helper contracts
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
📦 Bundle Size✅ No notable changes All bundles (14)
⚡ Performance (directional)✅ No significant change (within CI noise) All benchmarks (14)
Baseline: main @ 25f09ee · 2026-07-19 · gzipped is the headline size metric · perf is directional (shared-runner, gated) |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/unhead/src/define.ts (1)
4-6: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAlign
DefinedLinkunion distribution withDefinedScript.Currently,
DefinedLinkbehaves differently fromDefinedScriptwhen provided a discriminated union of objects (e.g.,cond ? { rel: 'preload' } : { rel: 'prefetch' }).Because
IsUnion<T['rel']>does not evaluate on a naked type parameterT, it prevents TypeScript from distributing the conditional type over the union. As a result, unions of objects collapse into the broadLinktype, whereasDefinedScriptcorrectly preserves the exact shapes of its constituent objects.To ensure consistent distribution behavior and properly preserve specific literal properties for object unions, consider structuring
DefinedLinkwithT extends { rel: infer U }to trigger conditional distribution:💡 Proposed refactor to align distribution behavior
-type DefinedLink<T extends { rel: string }> = IsUnion<T['rel']> extends false - ? T extends Link ? T : Link & Omit<T, 'rel'> - : Link & Omit<T, 'rel'> +type DefinedLink<T extends { rel: string }> = T extends { rel: infer U } + ? IsUnion<U> extends false + ? T extends Link ? T : Link & Omit<T, 'rel'> + : Link & Omit<T, 'rel'> + : never🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/unhead/src/define.ts` around lines 4 - 6, Update DefinedLink to use a distributive conditional based on T extending { rel: infer U }, matching the distribution pattern used by DefinedScript. Preserve the existing Link and Omit<T, 'rel'> behavior for each constituent while ensuring discriminated unions retain their specific object shapes and literal properties.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/unhead/src/define.ts`:
- Around line 4-6: Update DefinedLink to use a distributive conditional based on
T extending { rel: infer U }, matching the distribution pattern used by
DefinedScript. Preserve the existing Link and Omit<T, 'rel'> behavior for each
constituent while ensuring discriminated unions retain their specific object
shapes and literal properties.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 69174678-ed30-4c7e-9f49-0268dbd66de2
📒 Files selected for processing (2)
packages/unhead/src/define.tspackages/unhead/test/unit/types.test.ts
🔗 Linked issue
Related to #822
❓ Type of change
📚 Description
defineLink()anddefineScript()validate precise inputs but currently return the broadLinkandScriptunions, erasing literal and custom properties. This preserves validated properties for single known variants and custom inputs while keeping union discriminants and existingLink/Scriptassignability unchanged.Summary by CodeRabbit