Skip to content

fix(core): remove no-unsafe-type-assertion suppressions in JSON & Config utils#23628

Open
KumarADITHYA123 wants to merge 2 commits intogoogle-gemini:mainfrom
KumarADITHYA123:fix/unsafe-type-assertions-json-config
Open

fix(core): remove no-unsafe-type-assertion suppressions in JSON & Config utils#23628
KumarADITHYA123 wants to merge 2 commits intogoogle-gemini:mainfrom
KumarADITHYA123:fix/unsafe-type-assertions-json-config

Conversation

@KumarADITHYA123
Copy link
Copy Markdown
Contributor

SUMMARY

Fixes #19710

This removes all no-unsafe-type-assertion suppressions in safeJsonStringify.ts, schemaValidator.ts, and userAccountManager.ts. I replaced the unsafe casts with safe property narrowing using the in operator and type-guarded resolvers.

DETAILS

safeJsonStringify: Removed a pointless null check cast and unused imports.
schemaValidator: Replaced ESM to CJS interop casts with type-guarded resolver functions. Used in operator narrowing for schema URI access.
userAccountManager: Replaced Partial cast with in operator narrowing to safely extract and validate JSON properties with zero runtime overhead, unlike the previous PR which introduced Zod unnecessarily.

HOW TO VALIDATE

Typecheck:
npx tsc --noEmit --project packages/core/tsconfig.json

Lint:
npx eslint packages/core/src/utils/safeJsonStringify.ts packages/core/src/utils/schemaValidator.ts packages/core/src/utils/userAccountManager.ts

Tests:
npx vitest run packages/core/src/utils/safeJsonStringify.test.ts packages/core/src/utils/schemaValidator.test.ts packages/core/src/utils/userAccountManager.test.ts

@KumarADITHYA123 KumarADITHYA123 requested a review from a team as a code owner March 24, 2026 03:22
@gemini-code-assist
Copy link
Copy Markdown
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 type safety of core utility functions by systematically removing unsafe type assertions. It refactors code responsible for JSON serialization, schema validation, and user account data parsing to use more robust TypeScript patterns like type guards and property narrowing, leading to more reliable and maintainable code.

Highlights

  • Type Safety Enhancement: Eliminated all no-unsafe-type-assertion suppressions across safeJsonStringify.ts, schemaValidator.ts, and userAccountManager.ts.
  • Refactored Type Handling: Replaced unsafe type casts with robust type-guarded resolvers and safe property narrowing using the in operator.
  • Improved Code Clarity: Enhanced the reliability and maintainability of JSON serialization, schema validation, and user account data parsing utilities.
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.

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
Copy Markdown
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 effectively improves type safety across several utility files by removing unsafe type assertions. The changes in safeJsonStringify.ts, schemaValidator.ts, and userAccountManager.ts replace as casts and any types with safer alternatives like type guards, the in operator for property narrowing, and type-guarded resolvers for handling CJS/ESM module interop. These modifications are well-implemented and significantly enhance the robustness and maintainability of the code without introducing any issues.

@KumarADITHYA123
Copy link
Copy Markdown
Contributor Author

@jacob314 @spencer The previous author deleted their fork, which auto-closed PR #19746. I have fixed this correctly using safe property narrowing instead of adding Zod overhead. All CLI tests pass (43/43), PTAL.

@gemini-cli gemini-cli Bot added priority/p3 Backlog - a good idea but not currently a priority. area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! labels Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! priority/p3 Backlog - a good idea but not currently a priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix unsafe type assertions in Core Utilities (Phase 1.2: JSON & Config)

1 participant