Skip to content

fix(lint): no-explicit-any Diary, Exercises, Foods, Settings#832

Merged
CodeWithCJ merged 1 commit intoCodeWithCJ:mainfrom
Sim-sat:no-explicit-any-diary
Mar 3, 2026
Merged

fix(lint): no-explicit-any Diary, Exercises, Foods, Settings#832
CodeWithCJ merged 1 commit intoCodeWithCJ:mainfrom
Sim-sat:no-explicit-any-diary

Conversation

@Sim-sat
Copy link
Contributor

@Sim-sat Sim-sat commented Mar 3, 2026

Description

Removes explicit anys from Diary, Exercises, Foods and Settings.

Related Issue

PR type [ ] Issue [x] New Feature [ ] Documentation
Linked Issue: #795

Checklist

Please check all that apply:

  • [MANDATORY for new feature] Alignment: I have raised a GitHub issue and it was reviewed/approved by maintainers
  • Tests: I have included automated tests for my changes.
  • [MANDATORY for UI changes] Screenshots: I have attached "Before" vs "After" screenshots below.
  • [MANDATORY for Frontend changes] Quality: I have run pnpm run validate (especially for Frontend).
  • Translations: I have only updated the English (en) translation file (if applicable).
  • Architecture: My code follows the existing architecture standards.
  • Database Security: I have updated rls_policies.sql for any new user-specific tables.
  • [MANDATORY - ALL] Integrity & License: I certify this is my own work, free of malicious code(phishing, malware, etc.) and I agree to the License terms.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the frontend's type safety by systematically removing any type annotations across the Diary, Exercises, Foods, and Settings modules. This refactoring introduces more precise interfaces and type definitions, leading to a more robust, maintainable, and error-resistant codebase. The changes ensure that data structures and API responses are explicitly typed, improving developer experience and reducing potential runtime errors.

Highlights

  • Enhanced Type Safety in Diary Module: Replaced any return types with void or specific interfaces like Goals in foodEntryService.ts and mealTypeService.ts, improving type predictability for API calls. The Goals interface in diary.ts was also extended to include dietary_fiber and allow custom nutrients.
  • Improved Exercise Module Typing: Introduced several new interfaces (RawActivityDetail, RawExerciseSnapshot, RawExercise, RawGroupedEntry) in exerciseEntryService.ts to precisely type complex data structures, eliminating any in data mapping and API responses. exerciseSearchService.ts and workoutPresets.ts now use more specific Record types, and exerciseService.ts explicitly types exercise and failedRows.
  • Refined Food Module Type Definitions: Added NutritionixFood and NutritionixResponse interfaces in nutrionix.ts and RawUsdaNutrient, NutrientMap in usda.ts to provide strong typing for external API responses. mealPlanTemplate.ts and meals.ts were updated to remove any from parameter destructuring and API call parameters, respectively. Notably, the logMealPlanEntryToDiary function was removed from meals.ts.
  • Strengthened Settings Module Typing: Updated customCategoryService.ts and familyAccessService.ts to use specific CustomCategory and FamilyAccess types in array mapping. The preferences.ts file now imports UserPreferences and DefaultPreferences from dedicated services/contexts, and upsertUserPreferences is strongly typed. PreferencesContext.tsx saw significant updates, defining new unit and logging level types, and using DefaultPreferences for preference management.
Changelog
  • SparkyFitnessFrontend/src/api/Diary/foodEntryService.ts
    • Imported Goals type from diary.
    • Updated updateFoodEntry return type from any to void.
    • Updated createFoodEntry return type from any to void.
    • Updated removeFoodEntry return type from any to void.
    • Updated loadDiaryGoals return type from any to Goals.
    • Updated deleteFoodEntryMeal return type from any to void.
  • SparkyFitnessFrontend/src/api/Diary/mealTypeService.ts
    • Updated deleteMealType return type from any to void.
  • SparkyFitnessFrontend/src/api/Exercises/exerciseEntryService.ts
    • Added RawActivityDetail, RawExerciseSnapshot, RawExercise, and RawGroupedEntry interfaces.
    • Removed any type from response.map callback parameter.
    • Removed any type from entry.exercises.map callback parameter.
    • Removed any type from ex.activity_details.map callback parameter.
    • Removed any type from entryData[key] assignment.
    • Removed any type from entryData[key] assignment in updateExerciseEntry.
    • Expanded ActivityDetailsResponse interface with detailed nested types instead of [key: string]: any.
  • SparkyFitnessFrontend/src/api/Exercises/exerciseSearchService.ts
    • Updated params type from Record<string, any> to Record<string, string> in searchExercises.
    • Updated params type from Record<string, any> to Record<string, string | number> in searchExternalExercises.
  • SparkyFitnessFrontend/src/api/Exercises/exerciseService.ts
    • Updated exercise type from any to Exercise in parsedExercises mapping.
    • Updated failedRows type from any[] to unknown[] in ImportExercisesFromCSVResponse.
  • SparkyFitnessFrontend/src/api/Exercises/freeExerciseDB.ts
    • Updated cachedSchema type from any to unknown.
  • SparkyFitnessFrontend/src/api/Exercises/workoutPresets.ts
    • Updated params type from Record<string, any> to Record<string, string | number>.
  • SparkyFitnessFrontend/src/api/Foods/mealPlanTemplate.ts
    • Removed as any type assertion from templateData destructuring.
  • SparkyFitnessFrontend/src/api/Foods/meals.ts
    • Updated params type from { [key: string]: any } to { [key: string]: string }.
    • Removed logMealPlanEntryToDiary function.
  • SparkyFitnessFrontend/src/api/Foods/nutrionix.ts
    • Added NutritionixFood and NutritionixResponse interfaces.
    • Updated data type from any to NutritionixResponse in getNutritionixNutrients.
    • Updated data type from any to NutritionixResponse in getNutritionixBrandedNutrients.
  • SparkyFitnessFrontend/src/api/Foods/usda.ts
    • Added RawUsdaNutrient and NutrientMap interfaces.
    • Updated nutrientMap type from any to NutrientMap.
    • Updated n type from any to RawUsdaNutrient in foodNutrients.forEach.
  • SparkyFitnessFrontend/src/api/Settings/customCategoryService.ts
    • Updated cat type from any to CustomCategory in filter and map functions.
  • SparkyFitnessFrontend/src/api/Settings/familyAccessService.ts
    • Updated item type from any to FamilyAccess in transformedData mapping.
  • SparkyFitnessFrontend/src/api/Settings/preferences.ts
    • Removed local UserPreferences interface definition.
    • Imported DefaultPreferences and UserPreferences types.
    • Updated upsertUserPreferences payload type from any to Partial<DefaultPreferences> and return type from any to void.
  • SparkyFitnessFrontend/src/contexts/PreferencesContext.tsx
    • Imported CalorieGoalAdjustmentMode.
    • Defined new type aliases: WeightUnit, MeasurementUnit, DistanceUnit, LoggingLevel, calorieGoalAdjustmentMode, WaterDisplayUnit.
    • Updated PreferencesContextType properties and setter function parameters to use new specific unit and logging level types.
    • Defined DefaultPreferences interface.
    • Updated createDefaultPreferences to use Partial<DefaultPreferences>.
    • Updated updatePreferences parameter type from a large inline type to Partial<DefaultPreferences>.
    • Updated updateData type to Partial<DefaultPreferences>.
  • SparkyFitnessFrontend/src/pages/Diary/DiaryTopControls.tsx
    • Removed local Goals interface definition.
    • Imported Goals type from @/types/diary.
  • SparkyFitnessFrontend/src/types/diary.ts
    • Added dietary_fiber?: number; and [key: string]: number; to the Goals interface.
  • SparkyFitnessFrontend/src/types/exercises.ts
    • Added activity_details: ActivityDetailKeyValuePair[]; to the GroupedExerciseEntry interface.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request does a good job of removing explicit any types throughout the codebase, which improves type safety. I've identified a few areas where the changes introduce type inconsistencies or potential bugs. Specifically, several functions are now typed to return Promise<void> but still return a value. I've also found a couple of places where a necessary function call (parseJsonArray) was removed, which could lead to runtime errors. Additionally, there are some opportunities to further improve type safety with index access and a new required property that isn't always provided. My comments provide specific suggestions to address these points.

@Sim-sat Sim-sat force-pushed the no-explicit-any-diary branch from 6cdf247 to b5d69a4 Compare March 3, 2026 19:27
@CodeWithCJ CodeWithCJ merged commit 564eb42 into CodeWithCJ:main Mar 3, 2026
6 checks passed
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.

2 participants