fix(core): remove no-unsafe-type-assertion suppressions in JSON & Config utils#23628
Conversation
Summary of ChangesHello, 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
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
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