feat(search): add type inference for extraFields#3714
Conversation
|
@hendrikheil is attempting to deploy a commit to the Nuxt Team on Vercel. A member of the Team first needs to authorize it. |
commit: |
07028a6 to
94fb71c
Compare
94fb71c to
b0c2c9c
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR adds TypeScript overloads to the collection search API to enable type-safe access to extra fields. The generateSearchSections function in the search module now offers both a typed overload that accepts extraFields: K[] and narrows the return type to Section & Pick<T, K>, and a default overload for backward compatibility. The client and server wrappers (queryCollectionSearchSections) mirror these overloads to expose the same capability at the public API layer. Type re-exports of Section and GenerateSearchSectionsOptions are added across the modules to support the new type surface. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/runtime/internal/search.ts (1)
101-123: ⚡ Quick winAdd a type-level assertion for generateSearchSections's typed
extraFieldsoverload.
test/unit/generateSearchSections.test.tscoversextraFieldsbehavior at runtime, but there’s no type test that locks in theopts.extraFields: K[]overload’sSection & Pick<T, K>return type. Add a compile-time assertion (e.g.,expectTypeOf/tsd/@ts-expect-error) so the overload can’t silently widen back toSection[].🤖 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 `@src/runtime/internal/search.ts` around lines 101 - 123, Add a compile-time type assertion to the existing unit test so the typed overload of generateSearchSections keeps its narrowed return type: in test/unit/generateSearchSections.test.ts import a type-assertion helper (e.g., expectTypeOf or tsd) and add an assertion that calling generateSearchSections with opts.extraFields typed as K[] yields a value of type Array<Section & Pick<T, K>> (referencing generateSearchSections, Section, Pick, and the extraFields option). Ensure the assertion covers the generic overload (use a concrete PageCollectionItem-like type for T and a typed extraFields array) so TypeScript will error if the return type widens back to Section[].
🤖 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 `@src/runtime/internal/search.ts`:
- Around line 101-123: Add a compile-time type assertion to the existing unit
test so the typed overload of generateSearchSections keeps its narrowed return
type: in test/unit/generateSearchSections.test.ts import a type-assertion helper
(e.g., expectTypeOf or tsd) and add an assertion that calling
generateSearchSections with opts.extraFields typed as K[] yields a value of type
Array<Section & Pick<T, K>> (referencing generateSearchSections, Section, Pick,
and the extraFields option). Ensure the assertion covers the generic overload
(use a concrete PageCollectionItem-like type for T and a typed extraFields
array) so TypeScript will error if the return type widens back to Section[].
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 48944729-74a2-4d97-8fd5-a47219b70bad
📒 Files selected for processing (3)
src/runtime/client.tssrc/runtime/internal/search.tssrc/runtime/server.ts
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
🔗 Linked issue
❓ Type of change
📚 Description
Adds support for proper type inference for extraFields in generateSearchSections.
📝 Checklist