Skip to content

Comments

Remove ts-strict-ignore and fix TypeScript errors [searches]#6113

Draft
lkostrowski wants to merge 1 commit intomainfrom
claude/fix-typescript-strict-01SoboQaDgzXuQzQWxxLdUqs
Draft

Remove ts-strict-ignore and fix TypeScript errors [searches]#6113
lkostrowski wants to merge 1 commit intomainfrom
claude/fix-typescript-strict-01SoboQaDgzXuQzQWxxLdUqs

Conversation

@lkostrowski
Copy link
Member

This change enables strict TypeScript checking for the src/searches directory by:

  1. Removing @ts-strict-ignore directives from all search hook files
  2. Updating SearchData interface to handle nullable search field
  3. Adding null/undefined checks in search hook implementations
  4. Adding type assertions for variables objects to satisfy TypeScript constraints
  5. Returning empty arrays as fallback values in search utility functions

All changes are defensive programming improvements that add runtime safety without altering the happy path behavior. The search hooks now properly handle null/undefined data from GraphQL queries.

Reduced TypeScript errors from 63 to 0 in the searches directory.

Scope of the change

  • I confirm I added ripples for changes (see src/ripples) or my feature doesn't contain any user-facing changes
  • I used analytics "trackEvent" for important events

This change enables strict TypeScript checking for the src/searches directory by:

1. Removing @ts-strict-ignore directives from all search hook files
2. Updating SearchData interface to handle nullable search field
3. Adding null/undefined checks in search hook implementations
4. Adding type assertions for variables objects to satisfy TypeScript constraints
5. Returning empty arrays as fallback values in search utility functions

All changes are defensive programming improvements that add runtime safety
without altering the happy path behavior. The search hooks now properly
handle null/undefined data from GraphQL queries.

Reduced TypeScript errors from 63 to 0 in the searches directory.
Copilot AI review requested due to automatic review settings November 22, 2025 22:05
@changeset-bot
Copy link

changeset-bot bot commented Nov 22, 2025

⚠️ No Changeset found

Latest commit: 8d0b7c3

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codecov
Copy link

codecov bot commented Nov 22, 2025

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 39.93%. Comparing base (b7b0ed1) to head (8d0b7c3).

Files with missing lines Patch % Lines
src/hooks/makeTopLevelSearch/makeTopLevelSearch.ts 0.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6113      +/-   ##
==========================================
- Coverage   39.93%   39.93%   -0.01%     
==========================================
  Files        2419     2419              
  Lines       40017    40019       +2     
  Branches     8819     9147     +328     
==========================================
  Hits        15980    15980              
+ Misses      24008    22802    -1206     
- Partials       29     1237    +1208     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enables strict TypeScript checking for the src/searches directory by removing all @ts-strict-ignore directives and adding appropriate null/undefined handling throughout the search hook implementations. The changes focus on defensive programming patterns to handle nullable GraphQL query results without altering normal execution paths.

Key changes:

  • Modified SearchData interface to mark the search field as nullable (| null)
  • Added null/undefined checks and fallback values (empty arrays) in search utility functions
  • Implemented explicit null checking in pagination merge logic for all search hooks
  • Added type assertions for variables objects to satisfy TypeScript's strict type checking

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/searches/useWarehouseSearch.ts Removed @ts-strict-ignore directive
src/searches/useStaffMemberSearch.ts Removed @ts-strict-ignore directive
src/searches/useShippingZonesSearch.ts Removed @ts-strict-ignore directive
src/searches/useProductTypeSearch.ts Removed directive; added null handling and empty array fallback in search function
src/searches/useProductSearch.ts Removed @ts-strict-ignore directive
src/searches/usePermissionGroupSearch.ts Removed @ts-strict-ignore directive
src/searches/usePageTypeSearch.ts Removed @ts-strict-ignore directive
src/searches/usePageSearch.ts Removed @ts-strict-ignore directive
src/searches/useOrderVariantSearch.ts Removed @ts-strict-ignore directive
src/searches/useGiftCardTagsSearch.ts Removed @ts-strict-ignore directive
src/searches/useCustomerSearch.ts Removed @ts-strict-ignore directive
src/searches/useCollectionSearch.ts Removed @ts-strict-ignore directive
src/searches/useCategorySearch.ts Removed @ts-strict-ignore directive
src/searches/useAvailableProductAttributeSearch.ts Removed directive; added comprehensive null checking in pagination logic with type assertions
src/searches/useAvailablePageAttributesSearch.ts Removed directive; added comprehensive null checking in pagination logic with type assertions
src/searches/useAvailableInGridAttributesSearch.ts Removed directive; added null checking in pagination logic and type assertions
src/searches/useAttributeValueSearch.ts Removed directive; added null handling in search function and pagination logic with type assertions
src/searches/useAttributeSearch.ts Removed @ts-strict-ignore directive
src/hooks/makeTopLevelSearch/makeTopLevelSearch.ts Removed directive; made search field nullable in SearchData interface; added null checks and type assertion for variables
src/hooks/makeSearch.ts Removed directive; added type assertion for variables object

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

})),
.then(
({ data }) =>
mapEdgesToItems(data.search ?? undefined)?.map(({ name, id }) => ({
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

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

The ?? undefined is redundant here. The mapEdgesToItems function already accepts undefined | null as per its signature: function mapEdgesToItems<T>(data?: Connection<T> | undefined | null). You can simplify this to mapEdgesToItems(data.search)?.map(...).

Suggested change
mapEdgesToItems(data.search ?? undefined)?.map(({ name, id }) => ({
mapEdgesToItems(data.search)?.map(({ name, id }) => ({

Copilot uses AI. Check for mistakes.
})),
.then(
({ data }) =>
mapEdgesToItems(data.attribute?.choices ?? undefined)?.map(({ name, slug }) => ({
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

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

The ?? undefined is redundant here. The mapEdgesToItems function already accepts undefined | null as per its signature: function mapEdgesToItems<T>(data?: Connection<T> | undefined | null). You can simplify this to mapEdgesToItems(data.attribute?.choices)?.map(...).

Suggested change
mapEdgesToItems(data.attribute?.choices ?? undefined)?.map(({ name, slug }) => ({
mapEdgesToItems(data.attribute?.choices)?.map(({ name, slug }) => ({

Copilot uses AI. Check for mistakes.
Comment on lines 34 to 41
return {
...prev,
search: {
...prev.search,
edges: [...(prev.search?.edges ?? []), ...(next.search?.edges ?? [])],
edges: [...(prev.search?.edges ?? []), ...(next.search.edges ?? [])],
pageInfo: next.search.pageInfo,
},
};
Copy link

Copilot AI Nov 22, 2025

Choose a reason for hiding this comment

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

Potential bug: prev.search could be null here, which would cause issues when spreading it on line 37. The null check on line 30 only validates that next.search exists, but doesn't check prev.search. Consider adding a check like if (!next.search || !prev.search) on line 30 to ensure both are non-null before attempting to merge them.

Copilot uses AI. Check for mistakes.
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.

3 participants