fix: resolve TypeScript strict mode type errors

Fix 5 typecheck errors caught by tsc strict mode:
- Remove soundboard_play reference from types.test.ts
- Use optional chaining on MountableComponent.destroy
- Add string fallback for ROLE_COLORS lookup
- Add missing Channel fields in screen-share test mock
- Add non-null assertion on mock.calls index
This commit is contained in:
jevb
2026-04-01 11:51:07 +02:00
parent 87ba387623
commit c53035a4aa
6 changed files with 19 additions and 12 deletions
@@ -150,7 +150,7 @@ export function createUserBar(options?: UserBarOptions): MountableComponent {
}
function destroy(): void {
statusPicker?.destroy();
statusPicker?.destroy?.();
statusPicker = null;
disposable.destroy();
if (root !== null) {
@@ -209,7 +209,7 @@ export function createUserProfilePopup(
// Role badge
const roleBadge = createElement("span", { class: "upp-role-badge" });
const roleDot = createElement("span", { class: "upp-role-dot" });
roleDot.style.background = ROLE_COLORS[user.role] ?? ROLE_COLORS.member;
roleDot.style.background = ROLE_COLORS[user.role] ?? ROLE_COLORS.member ?? "";
const roleLabel = createElement(
"span",
{},
@@ -64,7 +64,18 @@ function setVoiceConnected(screenshare = false): void {
channelsStore.setState((prev) => ({
...prev,
channels: new Map([
[1, { id: 1, name: "Voice", type: "voice" as const, category: null, position: 0 }],
[
1,
{
id: 1,
name: "Voice",
type: "voice" as const,
category: null,
position: 0,
unreadCount: 0,
lastMessageId: null,
},
],
]),
}));
voiceStore.setState((prev) => ({
@@ -95,7 +95,7 @@ describe("StatusPicker wired to UserBar", () => {
(options[1] as HTMLElement).click(); // "Idle"
expect(ws.send).toHaveBeenCalledOnce();
const sentMsg = (ws.send as ReturnType<typeof vi.fn>).mock.calls[0][0];
const sentMsg = (ws.send as ReturnType<typeof vi.fn>).mock.calls[0]![0];
expect(sentMsg.type).toBe("presence_update");
expect(sentMsg.payload.status).toBe("idle");
});
+1 -5
View File
@@ -214,11 +214,7 @@ describe("ClientMessage types", () => {
};
expect(reactionAdd.type).toBe("reaction_add");
const soundboard: ClientMessage = {
type: "soundboard_play",
payload: { sound_id: "uuid-123" },
};
expect(soundboard.type).toBe("soundboard_play");
// soundboard_play type removed — see TODOS.md
});
it("includes voice mute type", () => {
@@ -55,7 +55,7 @@ describe("UserProfilePopup", () => {
expect(popupEl?.getAttribute("role")).toBe("dialog");
expect(popupEl?.getAttribute("aria-label")).toBe("User profile");
popup.destroy();
popup.destroy?.();
});
it("displays content correctly including status and join date", () => {
@@ -89,7 +89,7 @@ describe("UserProfilePopup", () => {
const callBtn = container.querySelector('[data-testid="upp-call-btn"]');
expect(callBtn).not.toBeNull();
popup.destroy();
popup.destroy?.();
});
it("outside click closes the popup", () => {
@@ -138,7 +138,7 @@ describe("UserProfilePopup", () => {
const avatar = container.querySelector(".upp-avatar") as HTMLElement;
expect(avatar.style.background).toBe("rgb(78, 80, 88)"); // #4e5058
popup.destroy();
popup.destroy?.();
});
it("Escape key closes the popup", () => {