-
Notifications
You must be signed in to change notification settings - Fork 13
fix: add TypeScript strict null checks to frontend hooks #271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,18 @@ import type { | |
| UpdateTask, | ||
| } from 'shared/types'; | ||
|
|
||
| // 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; | ||
|
Comment on lines
+19
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new helper returns a generic Useful? React with 👍 / 👎. |
||
| if (record.executor_profile && typeof record.executor_profile === 'object') { | ||
| const profile = record.executor_profile as Record<string, unknown>; | ||
| if (typeof profile.executor === 'string') return profile.executor; | ||
| } | ||
| return 'unknown'; | ||
| }; | ||
|
|
||
| export function useTaskMutations(projectId?: string) { | ||
| const queryClient = useQueryClient(); | ||
| const navigate = useNavigateWithSearch(); | ||
|
|
@@ -41,12 +53,9 @@ export function useTaskMutations(projectId?: string) { | |
| // Track task creation with analytics | ||
| // Note: executor info is not in CreateTask, will be tracked from config | ||
| trackTaskCreated({ | ||
| executor: (( | ||
| createdTask as Task & { executor_profile?: { executor?: string } } | ||
| ).executor_profile?.executor || | ||
| 'unknown') as import('@/types/analytics').ExecutorType, | ||
| executor: getExecutorString(createdTask), | ||
| has_description: !!variables.description, | ||
| prompt_length: variables.description?.length || 0, | ||
| prompt_length: variables.description?.length ?? 0, | ||
| is_subtask: !!variables.parent_task_attempt, | ||
| }); | ||
|
|
||
|
|
@@ -69,9 +78,9 @@ export function useTaskMutations(projectId?: string) { | |
| ) => { | ||
| // Track task creation with analytics | ||
| trackTaskCreated({ | ||
| executor: variables.executor_profile_id.executor || 'unknown', | ||
| executor: getExecutorString(variables.executor_profile_id), | ||
| has_description: !!variables.task.description, | ||
| prompt_length: variables.task.description?.length || 0, | ||
| prompt_length: variables.task.description?.length ?? 0, | ||
| is_subtask: !!variables.task.parent_task_attempt, | ||
| }); | ||
|
|
||
|
|
@@ -104,11 +113,7 @@ export function useTaskMutations(projectId?: string) { | |
| try { | ||
| const attempts = await attemptsApi.getAll(updatedTask.id); | ||
| const latestAttempt = attempts[0]; // Sorted newest first | ||
| const executorStr = | ||
| (latestAttempt as { executor?: string } | undefined)?.executor || | ||
| 'unknown'; | ||
| const executor = | ||
| executorStr as import('@/types/analytics').ExecutorType; | ||
| const executor = getExecutorString(latestAttempt); | ||
| const attemptCount = attempts.length; | ||
|
|
||
| trackTaskCompleted({ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new
getExecutorStringhelper returns a plainstring, but every analytics call here (trackTaskCreated,trackTaskCompleted,checkAndTrackFirstSuccess) still expects anExecutorTypeliteral union (frontend/src/types/analytics.ts). Withstrictmode enabled infrontend/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 toExecutorType(or cast) to keep the analytics payloads type-safe and compilable.Useful? React with 👍 / 👎.