Skip to content

feat(search): add type inference for extraFields#3714

Open
hendrikheil wants to merge 2 commits into
nuxt:mainfrom
hendrikheil:feat/search/extra-fields-type-inference
Open

feat(search): add type inference for extraFields#3714
hendrikheil wants to merge 2 commits into
nuxt:mainfrom
hendrikheil:feat/search/extra-fields-type-inference

Conversation

@hendrikheil
Copy link
Copy Markdown
Contributor

🔗 Linked issue

❓ Type of change

  • 📖 Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

Adds support for proper type inference for extraFields in generateSearchSections.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 6, 2026

@hendrikheil is attempting to deploy a commit to the Nuxt Team on Vercel.

A member of the Team first needs to authorize it.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Feb 6, 2026

npm i https://pkg.pr.new/@nuxt/content@3714

commit: 81b96b8

@hendrikheil hendrikheil force-pushed the feat/search/extra-fields-type-inference branch from 07028a6 to 94fb71c Compare June 1, 2026 07:59
@hendrikheil hendrikheil force-pushed the feat/search/extra-fields-type-inference branch from 94fb71c to b0c2c9c Compare June 1, 2026 08:19
@hendrikheil hendrikheil marked this pull request as ready for review June 1, 2026 08:22
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3143245f-35d9-4835-a8e2-202ab9c77a32

📥 Commits

Reviewing files that changed from the base of the PR and between b0c2c9c and 81b96b8.

📒 Files selected for processing (1)
  • test/unit/generateSearchSections.test.ts

📝 Walkthrough

Walkthrough

This 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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding type inference for extraFields in the search functionality.
Description check ✅ Passed The description directly addresses the changeset by explaining that it adds support for proper type inference for extraFields in generateSearchSections.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/runtime/internal/search.ts (1)

101-123: ⚡ Quick win

Add a type-level assertion for generateSearchSections's typed extraFields overload.

test/unit/generateSearchSections.test.ts covers extraFields behavior at runtime, but there’s no type test that locks in the opts.extraFields: K[] overload’s Section & 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 to Section[].

🤖 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

📥 Commits

Reviewing files that changed from the base of the PR and between 06f8edb and b0c2c9c.

📒 Files selected for processing (3)
  • src/runtime/client.ts
  • src/runtime/internal/search.ts
  • src/runtime/server.ts

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant