fix: add TypeScript strict null checks to frontend hooks#271
fix: add TypeScript strict null checks to frontend hooks#271jmanhype wants to merge 2 commits intoautomagik-dev:devfrom
Conversation
Summary of ChangesHello @jmanhype, 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 focuses on improving the robustness and type safety of several frontend hooks by addressing potential 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. 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces several important fixes for strict null-check compliance across various frontend hooks. The changes effectively prevent potential runtime errors by safely handling nullable values from API responses and refs. The introduction of the getExecutorString helper in useTaskMutations is a great refactoring that centralizes logic for extracting executor information. The use of type guards in useDiffStream and consistent use of nullish coalescing (??) are also welcome improvements for type safety and code clarity. Overall, these are solid changes that increase the robustness of the codebase. I have one minor suggestion for cleanup.
frontend/src/hooks/useDiffStream.ts
Outdated
| return Object.values(data?.entries ?? {}) | ||
| .filter((entry) => entry?.type === 'DIFF') | ||
| .filter((entry): entry is PatchType & { type: 'DIFF'; content: Diff } => | ||
| entry?.type === 'DIFF' && entry.content != null |
There was a problem hiding this comment.
The optional chaining on entry is not necessary here. Object.values(data?.entries ?? {}) will produce an array of PatchType objects, which are guaranteed to be non-null from the stream. Removing the ? makes the code slightly cleaner and more precise about the expected types.
| entry?.type === 'DIFF' && entry.content != null | |
| entry.type === 'DIFF' && entry.content != null |
- useAgentTasks: add null check for executor.split() to prevent runtime errors when executor is undefined - useConversationHistory: fix console.warn! typo and improve null checks for executionProcesses.current access patterns - useTaskMutations: add getExecutorString helper for safe executor extraction, replace || with ?? for better nullish handling - useDiffStream: add type guard to ensure entry.content is not null before mapping These changes prevent potential runtime errors when handling API responses that may contain null/undefined values. Co-authored-by: Automagik Genie 🧞 <genie@namastex.ai>
- Remove optional chaining on entry?.type since Object.values() produces non-null array items - Keeps type guard for better type safety - Addresses Gemini Code Assist feedback Co-authored-by: Automagik Genie 🧞 <genie@namastex.ai>
66e2c84 to
63dfebd
Compare
|
@codex review this pr |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // Helper to safely extract executor string from various object shapes | ||
| const getExecutorString = (obj: unknown): string => { | ||
| if (!obj || typeof obj !== 'object') return 'unknown'; | ||
| const record = obj as Record<string, unknown>; | ||
| if (typeof record.executor === 'string') return record.executor; |
There was a problem hiding this comment.
Narrow executor type to satisfy analytics events
The new getExecutorString helper returns a plain string, but every analytics call here (trackTaskCreated, trackTaskCompleted, checkAndTrackFirstSuccess) still expects an ExecutorType literal union (frontend/src/types/analytics.ts). With strict mode enabled in frontend/tsconfig.json, the widened return type causes TypeScript to reject these calls, so the build will now fail before runtime. The helper should return/validate to ExecutorType (or cast) to keep the analytics payloads type-safe and compilable.
Useful? React with 👍 / 👎.
|
@codex review this pr |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // Helper to safely extract executor string from various object shapes | ||
| const getExecutorString = (obj: unknown): string => { | ||
| if (!obj || typeof obj !== 'object') return 'unknown'; | ||
| const record = obj as Record<string, unknown>; | ||
| if (typeof record.executor === 'string') return record.executor; |
There was a problem hiding this comment.
getExecutorString returns plain string breaking ExecutorType checks
The new helper returns a generic string, but the analytics events you pass it into (trackTaskCreated and trackTaskCompleted) require executor to be the ExecutorType literal union defined in frontend/src/types/analytics.ts. With this change the call sites now infer executor as string, so a TypeScript type-check (or ESLint with type information) will fail with Type 'string' is not assignable to type 'ExecutorType', blocking the build. Please type the helper to return ExecutorType (or cast its result) so the calls satisfy the expected union.
Useful? React with 👍 / 👎.
These changes prevent potential runtime errors when handling API responses that may contain null/undefined values.