refactor(food): add explicit return types to repository helpers#1456
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
…ories Co-authored-by: marcuscastelo <27441558+marcuscastelo@users.noreply.github.com>
6b5c7b8
into
marcuscastelo/issue1447-remove-shims
There was a problem hiding this comment.
Pull request overview
This PR enhances type safety in the diet/food infrastructure by adding explicit Promise<readonly Food[]> return types to two previously untyped helper functions in supabaseFoodRepository.ts. These changes align with the broader encapsulation refactoring effort where repository implementations use factory functions and keep helpers file-local.
Key changes:
- Added explicit return type annotations to
fetchFoodsByNameandfetchFoodshelper functions - Return types correctly specify
Promise<readonly Food[]>, matching the actual implementation and interface contract
| async function fetchFoodsByName( | ||
| name: Required<Food>['name'], | ||
| params: FoodSearchParams = {}, | ||
| ) { | ||
| ): Promise<readonly Food[]> { |
There was a problem hiding this comment.
The fetchFoodsByName function lacks JSDoc documentation, creating inconsistency with other repository helper functions like fetchFoodById, fetchFoodByEan, and fetchFoodsByIds which all have comprehensive JSDoc. Consider adding documentation following the same pattern:
/**
* Fetches Foods by name using enhanced search with scoring.
* Supports both regular search and favorites-only search.
* @param name - The food name to search for
* @param params - Optional search parameters (userId, isFavoritesSearch, limit)
* @returns Array of matching Foods
* @throws Error on API/validation error
*/
async function fetchFoodsByName(
name: Required<Food>['name'],
params: FoodSearchParams = {},
): Promise<readonly Food[]> {| @@ -172,7 +172,9 @@ async function fetchFoodsByName( | |||
| } | |||
| } | |||
|
|
|||
There was a problem hiding this comment.
The fetchFoods function lacks JSDoc documentation, creating inconsistency with other repository helper functions. Consider adding documentation following the pattern used elsewhere in this file:
/**
* Fetches all Foods with optional filtering.
* @param params - Optional search parameters (limit, allowedFoods, etc.)
* @returns Array of Foods
* @throws Error on API/validation error
*/
async function fetchFoods(
params: FoodSearchParams = {},
): Promise<readonly Food[]> {| /** | |
| * Fetches all Foods with optional filtering. | |
| * @param params - Optional search parameters (limit, allowedFoods, etc.) | |
| * @returns Array of Foods | |
| * @throws Error on API/validation error | |
| */ |
The
diet/foodinfrastructure already encapsulated helper functions correctly—all were file-local with only factory functions exported. Added missing explicit return types for type safety.Changes
Promise<readonly Food[]>return types tofetchFoodsandfetchFoodsByNameBefore:
After:
All repository consumers correctly use factory-returned instances.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.