Skip to content

Commit 2e353dd

Browse files
Copilothotlong
andcommitted
Replace type assertions with runtime validation in AppHeader.tsx
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent 225d7c7 commit 2e353dd

2 files changed

Lines changed: 37 additions & 409 deletions

File tree

apps/console/src/components/AppHeader.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,20 @@ export function AppHeader({ appName, objects, connectionState, presenceUsers, ac
6666
dataSource.find('sys_presence').catch(() => ({ data: [] })),
6767
dataSource.find('sys_activity', { $orderby: { timestamp: 'desc' }, $top: 20 }).catch(() => ({ data: [] })),
6868
]);
69-
if (presenceResult.data?.length) setApiPresenceUsers(presenceResult.data as PresenceUser[]);
70-
if (activityResult.data?.length) setApiActivities(activityResult.data as ActivityItem[]);
69+
if (presenceResult.data?.length) {
70+
const data = presenceResult.data as Record<string, unknown>[];
71+
const users = data.filter(
72+
(u): u is PresenceUser & Record<string, unknown> => typeof u.userId === 'string'
73+
);
74+
if (users.length) setApiPresenceUsers(users);
75+
}
76+
if (activityResult.data?.length) {
77+
const data = activityResult.data as Record<string, unknown>[];
78+
const items = data.filter(
79+
(a): a is ActivityItem & Record<string, unknown> => typeof a.type === 'string'
80+
);
81+
if (items.length) setApiActivities(items);
82+
}
7183
} catch {
7284
// Fallback to defaults handled below
7385
}

0 commit comments

Comments
 (0)