Skip to content

fix(lint): remove first batch of explicit anys#823

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

fix(lint): remove first batch of explicit anys#823
CodeWithCJ merged 1 commit intoCodeWithCJ:mainfrom
Sim-sat:no-explicit-any

Conversation

@Sim-sat
Copy link
Contributor

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

Description

Removes 52 explicit anys from the code. I focused on the error types only. If the types don't match they could lead to crashes of the app when an error is thrown. I added a helper function to extract the messages.

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 improves the frontend's error handling by migrating from the less safe any type to unknown in catch blocks. This change, coupled with the introduction of a new getErrorMessage utility, ensures that errors are handled with greater type safety and consistency, reducing the likelihood of unexpected application crashes due to improperly typed error objects. The refactoring touches various API service files, authentication components, and settings pages, standardizing how errors are processed and displayed to the user.

Highlights

  • Improved Type Safety in Error Handling: Replaced 52 instances of explicit any types in catch blocks with the more type-safe unknown type, enhancing error handling robustness and preventing potential runtime issues.
  • New Error Message Utility: Introduced a new utility function, getErrorMessage, in src/utils/api.ts to safely extract error messages from unknown error types, promoting consistent error reporting across the application.
  • New Type Guard Utility: Added an isObject type guard utility function in src/utils/api.ts to safely check if a value is an object, which is used in complex error handling scenarios.
  • Consistent Error Message Extraction: Updated numerous files to utilize the new getErrorMessage utility when processing caught errors, ensuring a standardized approach to error message retrieval.
Changelog
  • SparkyFitnessFrontend/src/api/Chatbot/Chatbot_ExerciseHandler.ts
    • Updated error catch blocks from any to unknown to improve type safety.
  • SparkyFitnessFrontend/src/api/Chatbot/Chatbot_FoodHandler.ts
    • Updated error catch blocks from any to unknown to improve type safety.
  • SparkyFitnessFrontend/src/api/Chatbot/Chatbot_MeasurementHandler.ts
    • Imported getErrorMessage utility.
    • Updated error catch blocks to unknown and utilized getErrorMessage for consistent error message extraction.
  • SparkyFitnessFrontend/src/api/Chatbot/sparkyChatService.ts
    • Imported getErrorMessage utility.
    • Updated error catch blocks to unknown and utilized getErrorMessage for consistent error message extraction.
  • SparkyFitnessFrontend/src/api/CheckIn/moodService.ts
    • Imported getErrorMessage utility.
    • Updated error catch blocks to unknown and utilized getErrorMessage for consistent error message extraction.
  • SparkyFitnessFrontend/src/api/Diary/dailyProgressService.ts
    • Imported getErrorMessage utility.
    • Updated error catch blocks to unknown and utilized getErrorMessage for consistent error message extraction.
  • SparkyFitnessFrontend/src/api/Settings/aiServiceSettingsService.ts
    • Imported getErrorMessage utility.
    • Updated error catch blocks to unknown and utilized getErrorMessage for consistent error message extraction.
  • SparkyFitnessFrontend/src/api/api.ts
    • Updated error catch blocks from any to unknown to improve type safety.
  • SparkyFitnessFrontend/src/components/OidcCallback.tsx
    • Imported getErrorMessage utility.
    • Updated error catch blocks to unknown and utilized getErrorMessage for consistent error message extraction.
  • SparkyFitnessFrontend/src/contexts/PreferencesContext.tsx
    • Imported getErrorMessage utility.
    • Updated error catch blocks from any to unknown and utilized getErrorMessage for consistent error message extraction.
  • SparkyFitnessFrontend/src/pages/Admin/OidcSettings.tsx
    • Updated error catch blocks from any to untyped catch.
  • SparkyFitnessFrontend/src/pages/Auth/Auth.tsx
    • Imported getErrorMessage utility.
    • Updated error catch blocks to unknown, adding instanceof Error checks and utilizing getErrorMessage for message extraction.
  • SparkyFitnessFrontend/src/pages/Auth/ForgotPassword.tsx
    • Imported getErrorMessage utility.
    • Updated error catch blocks to unknown and utilized getErrorMessage for consistent error message extraction.
  • SparkyFitnessFrontend/src/pages/Auth/MfaChallenge.tsx
    • Imported getErrorMessage utility.
    • Updated error catch blocks to unknown and utilized getErrorMessage for consistent error message extraction.
  • SparkyFitnessFrontend/src/pages/Auth/ResetPassword.tsx
    • Imported getErrorMessage utility.
    • Updated error catch blocks to unknown and utilized getErrorMessage for consistent error message extraction.
  • SparkyFitnessFrontend/src/pages/Exercises/ExerciseEntryHistoryImportCSV.tsx
    • Imported isObject utility.
    • Defined ImportCsvError interface for type-safe error handling.
    • Updated error catch blocks to unknown and used isObject for type-safe access to error details.
  • SparkyFitnessFrontend/src/pages/Integrations/FitbitCallback.tsx
    • Updated error catch blocks from any to unknown to improve type safety.
  • SparkyFitnessFrontend/src/pages/Integrations/PolarCallback.tsx
    • Updated error catch blocks from any to unknown to improve type safety.
  • SparkyFitnessFrontend/src/pages/Integrations/StravaCallback.tsx
    • Updated error catch blocks from any to unknown to improve type safety.
  • SparkyFitnessFrontend/src/pages/Settings/ExternalProviderList.tsx
    • Updated error catch blocks from any to unknown to improve type safety.
  • SparkyFitnessFrontend/src/pages/Settings/MFASettings.tsx
    • Imported getErrorMessage utility.
    • Updated error catch blocks to unknown and utilized getErrorMessage for consistent error message extraction.
  • SparkyFitnessFrontend/src/pages/Settings/NutrientDisplaySettings.tsx
    • Imported getErrorMessage utility.
    • Updated error catch blocks to unknown and utilized getErrorMessage for consistent error message extraction.
  • SparkyFitnessFrontend/src/utils/api.ts
    • Added getErrorMessage utility function to safely extract messages from unknown error types.
    • Added isObject type guard utility function for robust object checks.
Activity
  • Sim-sat created this pull request to address linting issues by removing explicit any types in error handling.
  • The pull request description indicates that 52 explicit any types were removed, specifically focusing on error types to prevent application crashes.
  • A new helper function was added to extract error messages safely.
  • The author confirmed running pnpm run validate and adhering to existing architecture standards.
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 great job of removing explicit any types, primarily in catch blocks, and replacing them with unknown. This significantly improves type safety. The introduction of the getErrorMessage and isObject utility functions is a solid approach to safely handle and inspect errors of unknown type. The changes are consistent across many files. I have a few minor suggestions for improvement in SparkyFitnessFrontend/src/pages/Exercises/ExerciseEntryHistoryImportCSV.tsx regarding code organization, comments, and ensuring robustness in internationalization calls.

@CodeWithCJ CodeWithCJ merged commit d20eb7a into CodeWithCJ:main Mar 2, 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