fix(types): enforce required as attribute for preload links#683
Conversation
Add `BareAlternateLink` for bare `rel="alternate"` links without hreflang/type/media. Add `KnownLinkRel` union type enumerating all known rel values. Update `PreloadLink` subtypes to correctly require `as` when used directly. Improve `GenericLink` and `Link` JSDoc to clarify the `as`-for-preload enforcement through the `PreloadLink` type union. Add type tests verifying `PreloadLink` rejects missing `as` at compile time. Fix tests using preload links without `as` (capo) and font preloads without `crossorigin` (benchmark) to match correct HTML semantics. Use `as const` in tests where TypeScript widened rel to `string` (keys, deduping). Use type assertion in `useScript` warmup for the runtime-conditional link object. Closes #527
|
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 (9)
📝 WalkthroughWalkthroughThe changes introduce type-level enforcement for conditional link attributes, specifically requiring the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 Analysis
|
🔗 Linked issue
Resolves #527
❓ Type of change
📚 Description
The
PreloadLinkdiscriminated union types already requiredas, butGenericLink(the catch-all withrel: string) absorbed preload objects bypassing the requirement. AddedKnownLinkReltype union,BareAlternateLinkfor real-world alternate usage, and documented the TypeScript limitation whereGenericLinkabsorbs literal rel values. UsingPreloadLinkdirectly now correctly enforcesas. Also fixed several existing tests that had incorrect preload links missingasorcrossorigin.Summary by CodeRabbit
New Features
BareAlternateLink,KnownLinkRel, andPreloadLinkfor enhanced type safety and flexibility.Refactor
Tests