Skip to content

Commit c22c2cf

Browse files
ericallamclaude
andcommitted
Fix TypeScript errors in sort functions
- Add type predicates to filter functions for proper type narrowing - Add type assertions for tuple index accesses in sort comparisons Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent a66bb6f commit c22c2cf

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

apps/webapp/app/services/runsReplicationService.server.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -576,32 +576,44 @@ export class RunsReplicationService {
576576

577577
const taskRunInserts = preparedInserts
578578
.map(({ taskRunInsert }) => taskRunInsert)
579-
.filter(Boolean)
579+
.filter((x): x is TaskRunInsertArray => Boolean(x))
580580
// batch inserts in clickhouse are more performant if the items
581581
// are pre-sorted by the primary key
582582
.sort((a, b) => {
583-
if (a[TASK_RUN_INDEX.organization_id] !== b[TASK_RUN_INDEX.organization_id]) {
584-
return a[TASK_RUN_INDEX.organization_id] < b[TASK_RUN_INDEX.organization_id] ? -1 : 1;
583+
const aOrgId = a[TASK_RUN_INDEX.organization_id] as string;
584+
const bOrgId = b[TASK_RUN_INDEX.organization_id] as string;
585+
if (aOrgId !== bOrgId) {
586+
return aOrgId < bOrgId ? -1 : 1;
585587
}
586-
if (a[TASK_RUN_INDEX.project_id] !== b[TASK_RUN_INDEX.project_id]) {
587-
return a[TASK_RUN_INDEX.project_id] < b[TASK_RUN_INDEX.project_id] ? -1 : 1;
588+
const aProjId = a[TASK_RUN_INDEX.project_id] as string;
589+
const bProjId = b[TASK_RUN_INDEX.project_id] as string;
590+
if (aProjId !== bProjId) {
591+
return aProjId < bProjId ? -1 : 1;
588592
}
589-
if (a[TASK_RUN_INDEX.environment_id] !== b[TASK_RUN_INDEX.environment_id]) {
590-
return a[TASK_RUN_INDEX.environment_id] < b[TASK_RUN_INDEX.environment_id] ? -1 : 1;
593+
const aEnvId = a[TASK_RUN_INDEX.environment_id] as string;
594+
const bEnvId = b[TASK_RUN_INDEX.environment_id] as string;
595+
if (aEnvId !== bEnvId) {
596+
return aEnvId < bEnvId ? -1 : 1;
591597
}
592-
if (a[TASK_RUN_INDEX.created_at] !== b[TASK_RUN_INDEX.created_at]) {
593-
return a[TASK_RUN_INDEX.created_at] - b[TASK_RUN_INDEX.created_at];
598+
const aCreatedAt = a[TASK_RUN_INDEX.created_at] as number;
599+
const bCreatedAt = b[TASK_RUN_INDEX.created_at] as number;
600+
if (aCreatedAt !== bCreatedAt) {
601+
return aCreatedAt - bCreatedAt;
594602
}
595-
return a[TASK_RUN_INDEX.run_id] < b[TASK_RUN_INDEX.run_id] ? -1 : 1;
603+
const aRunId = a[TASK_RUN_INDEX.run_id] as string;
604+
const bRunId = b[TASK_RUN_INDEX.run_id] as string;
605+
return aRunId < bRunId ? -1 : 1;
596606
});
597607

598608
const payloadInserts = preparedInserts
599609
.map(({ payloadInsert }) => payloadInsert)
600-
.filter(Boolean)
610+
.filter((x): x is PayloadInsertArray => Boolean(x))
601611
// batch inserts in clickhouse are more performant if the items
602612
// are pre-sorted by the primary key
603613
.sort((a, b) => {
604-
return a[PAYLOAD_INDEX.run_id] < b[PAYLOAD_INDEX.run_id] ? -1 : 1;
614+
const aRunId = a[PAYLOAD_INDEX.run_id] as string;
615+
const bRunId = b[PAYLOAD_INDEX.run_id] as string;
616+
return aRunId < bRunId ? -1 : 1;
605617
});
606618

607619
span.setAttribute("task_run_inserts", taskRunInserts.length);

0 commit comments

Comments
 (0)