fix(types): prevent string widening in SpeculationRules nested types#737
fix(types): prevent string widening in SpeculationRules nested types#737
Conversation
Merges SpeculationRuleBase, SpeculationRuleList, and SpeculationRuleDocument into a single SpeculationRule interface. Discrimination is now structural (urls vs where) rather than relying on literal source values that TypeScript widens to string inside useHead, breaking the discriminated union.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe SpeculationRules schema consolidates three separate interfaces ( Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 Analysis
|
🔗 Linked issue
N/A
❓ Type of change
📚 Description
When using
useHeadwith speculation rules, TypeScript widens nested literal values likesource: 'list'andrequires: ['anonymous-client-ip-when-cross-origin']tostring, which fails to match the discriminated union ofSpeculationRuleList | SpeculationRuleDocument. This causes a type error that falls through toApplicationJsonScript.Merges
SpeculationRuleBase,SpeculationRuleList, andSpeculationRuleDocumentinto a singleSpeculationRuleinterface. Discrimination is now structural (urlsvswherepresence) rather than relying on literalsourcevalues. Fields that previously required exact literals (source,requires,relative_to,target_hint) now use the(string & Record<never, never>)pattern already established throughout the codebase for autocomplete with flexible matching.Summary by CodeRabbit
prefetchandprerenderconfiguration in speculation rules to use a unified interface supporting both list and document-based rules.