Remove ts-strict-ignore and fix TypeScript errors [searches]#6113
Remove ts-strict-ignore and fix TypeScript errors [searches]#6113lkostrowski wants to merge 1 commit intomainfrom
Conversation
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.
|
|
|
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
SearchDatainterface to mark thesearchfield 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 }) => ({ |
There was a problem hiding this comment.
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(...).
| mapEdgesToItems(data.search ?? undefined)?.map(({ name, id }) => ({ | |
| mapEdgesToItems(data.search)?.map(({ name, id }) => ({ |
| })), | ||
| .then( | ||
| ({ data }) => | ||
| mapEdgesToItems(data.attribute?.choices ?? undefined)?.map(({ name, slug }) => ({ |
There was a problem hiding this comment.
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(...).
| mapEdgesToItems(data.attribute?.choices ?? undefined)?.map(({ name, slug }) => ({ | |
| mapEdgesToItems(data.attribute?.choices)?.map(({ name, slug }) => ({ |
| return { | ||
| ...prev, | ||
| search: { | ||
| ...prev.search, | ||
| edges: [...(prev.search?.edges ?? []), ...(next.search?.edges ?? [])], | ||
| edges: [...(prev.search?.edges ?? []), ...(next.search.edges ?? [])], | ||
| pageInfo: next.search.pageInfo, | ||
| }, | ||
| }; |
There was a problem hiding this comment.
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.
This change enables strict TypeScript checking for the src/searches directory by:
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