Skip to content

Commit 7fbcb7d

Browse files
committed
refactor: fix all type warnings from nuxt typecheck
1 parent 7c8ff0b commit 7fbcb7d

10 files changed

Lines changed: 40 additions & 34 deletions

File tree

app/components/Ui/ListModal.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
class="item"
1414
:style="{
1515
'--percentage': `${
16-
sortedItems.length > 0 && sortedItems[0].seconds > 0
17-
? ((item.seconds / sortedItems[0].seconds) * 100).toFixed(1)
16+
maxSeconds > 0
17+
? ((item.seconds / maxSeconds) * 100).toFixed(1)
1818
: 0
1919
}%`,
2020
}">
@@ -67,6 +67,8 @@ const sortedItems = computed(() => {
6767
return [...props.items].sort((a, b) => b.seconds - a.seconds);
6868
});
6969
70+
const maxSeconds = computed(() => sortedItems.value[0]?.seconds ?? 0);
71+
7072
const calculatePercentage = (seconds: number): string => {
7173
if (props.totalSeconds === 0) return "0.0";
7274
return ((seconds / props.totalSeconds) * 100).toFixed(1);

app/composables/useStats.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import { computed } from "vue";
2+
import type { Ref } from "vue";
3+
4+
declare function useState<T>(key: string, init: () => T): Ref<T>;
5+
declare function useRequestURL(): URL;
26
import type { User } from "~~/prisma/generated/client";
37

48
export const TimeRangeEnum = {
@@ -125,7 +129,7 @@ export const useStats = () => {
125129
const requestURL = useRequestURL();
126130
baseUrl = requestURL.origin;
127131
} else {
128-
baseUrl = window.location.origin;
132+
baseUrl = location.origin;
129133
}
130134

131135
const url = new URL("/api/stats", baseUrl);
@@ -159,7 +163,7 @@ export const useStats = () => {
159163
err instanceof Error &&
160164
err.message.includes("401")
161165
) {
162-
window.location.href = "/login";
166+
(location as { href: string }).href = "/login";
163167
}
164168
}
165169
};

server/api/import/index.post.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { tmpdir } from "os";
1717
import fs from "fs";
1818
import type { WakatimeExportData } from "~~/server/utils/wakatime";
1919
import busboy from "busboy";
20-
import { ImportJob, ImportStatus } from "~~/types/import";
20+
import { type ImportJob, ImportStatus } from "~~/types/import";
2121

2222
async function safeReadMultipartFormData(event: H3Event): Promise<any[]> {
2323
const contentLength = getHeader(event, "content-length");
@@ -447,8 +447,8 @@ async function processFileInBackground(fileId: string, userId: string) {
447447
.readdirSync(chunksDir)
448448
.filter((file) => file.startsWith("chunk-"))
449449
.sort((a, b) => {
450-
const indexA = parseInt(a.split("-")[1]);
451-
const indexB = parseInt(b.split("-")[1]);
450+
const indexA = parseInt(a.split("-")[1] ?? "0");
451+
const indexB = parseInt(b.split("-")[1] ?? "0");
452452
return indexA - indexB;
453453
});
454454

server/api/import/status.get.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createEventStream, getRequestHeader } from "h3";
2-
import type { User } from "@prisma/client";
2+
import type { User } from "~~/prisma/generated/client";
33

44
import { handleLog } from "~~/server/utils/logging";
55
import {

server/cron/summarize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export default defineCronHandler(
7676
});
7777

7878
for (const userId in userHeartbeats) {
79-
await processSummariesByDate(userId, userHeartbeats[userId]);
79+
await processSummariesByDate(userId, userHeartbeats[userId]!);
8080
}
8181

8282
if (heartbeatsToSummarize.length < BATCH_SIZE) {

server/utils/import-queue.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
handleWakApiSequentialImport,
1515
prepareWakApiData,
1616
} from "./wakapi";
17-
import { ImportJob, ImportStatus, JobUpdateOptions, QueueJob, WorkChunk } from "~~/types/import";
17+
import { type ImportJob, ImportStatus, type JobUpdateOptions, type QueueJob, type WorkChunk } from "~~/types/import";
1818

1919
export const activeJobs = new Map<string, ImportJob>();
2020

@@ -233,7 +233,7 @@ class ImportQueue {
233233
});
234234

235235
worker.on("error", (error) => {
236-
handleLog(`Worker thread ${workerId} error: ${error.message}`);
236+
handleLog(`Worker thread ${workerId} error: ${(error as Error).message}`);
237237
this.restartWorkerThread(workerId);
238238
});
239239

server/utils/stats.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TimeRange } from "~/composables/useStats";
1+
import type { TimeRange } from "~/composables/useStats";
22
import { prisma } from "~~/prisma/db";
33

44
export async function calculateStats(
@@ -96,10 +96,10 @@ export async function getUserTimeRangeTotal(
9696
}
9797

9898
return {
99-
totalMinutes: result[0].total_minutes,
100-
totalHours: result[0].total_hours,
101-
startDate: result[0].start_date,
102-
endDate: result[0].end_date,
99+
totalMinutes: result[0]!.total_minutes,
100+
totalHours: result[0]!.total_hours,
101+
startDate: result[0]!.start_date,
102+
endDate: result[0]!.end_date,
103103
};
104104
} catch (error) {
105105
console.error("Error getting time range total:", error);

server/utils/summarize.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Heartbeats, Summaries } from "~~/prisma/generated/client";
1+
import type { Heartbeats, Summaries } from "~~/prisma/generated/client";
22
import { prisma } from "~~/prisma/db";
33

44
export function calculateTotalMinutesFromHeartbeats(
@@ -123,27 +123,27 @@ export function calculateCategoryTimes(
123123
}
124124

125125
Object.keys(projectsTime).forEach((key) => {
126-
projectsTime[key] = Math.round(projectsTime[key]);
126+
projectsTime[key] = Math.round(projectsTime[key]!);
127127
});
128128

129129
Object.keys(editorsTime).forEach((key) => {
130-
editorsTime[key] = Math.round(editorsTime[key]);
130+
editorsTime[key] = Math.round(editorsTime[key]!);
131131
});
132132

133133
Object.keys(languagesTime).forEach((key) => {
134-
languagesTime[key] = Math.round(languagesTime[key]);
134+
languagesTime[key] = Math.round(languagesTime[key]!);
135135
});
136136

137137
Object.keys(osTime).forEach((key) => {
138-
osTime[key] = Math.round(osTime[key]);
138+
osTime[key] = Math.round(osTime[key]!);
139139
});
140140

141141
Object.keys(filesTime).forEach((key) => {
142-
filesTime[key] = Math.round(filesTime[key]);
142+
filesTime[key] = Math.round(filesTime[key]!);
143143
});
144144

145145
Object.keys(branchesTime).forEach((key) => {
146-
branchesTime[key] = Math.round(branchesTime[key]);
146+
branchesTime[key] = Math.round(branchesTime[key]!);
147147
});
148148

149149
return {
@@ -488,7 +488,7 @@ export async function processHeartbeatsByDate(
488488

489489
heartbeats.forEach((heartbeat) => {
490490
const date = new Date(heartbeat.timestamp);
491-
const dateKey = date.toISOString().split("T")[0];
491+
const dateKey = date.toISOString().split("T")[0]!;
492492

493493
if (!heartbeatsByDate.has(dateKey)) {
494494
heartbeatsByDate.set(dateKey, []);
@@ -512,7 +512,7 @@ export async function processSummariesByDate(
512512

513513
heartbeats.forEach((heartbeat) => {
514514
const date = new Date(heartbeat.timestamp);
515-
const dateKey = date.toISOString().split("T")[0];
515+
const dateKey = date.toISOString().split("T")[0]!;
516516

517517
if (!heartbeatsByDate.has(dateKey)) {
518518
heartbeatsByDate.set(dateKey, []);

server/utils/wakapi.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { processHeartbeatsByDate } from "~~/server/utils/summarize";
44
import { handleApiError, handleLog } from "~~/server/utils/logging";
55
import { activeJobs, updateJob } from "~~/server/utils/import-queue";
66
import { randomUUID } from "crypto";
7-
import { ImportJob, ImportStatus } from "~~/types/import";
7+
import { type ImportJob, ImportStatus } from "~~/types/import";
88

99
interface WakApiHeartbeat {
1010
id: string;
@@ -61,19 +61,19 @@ async function fetchWakApiHeartbeats(
6161
const allDateStrings: string[] = [];
6262
const currentDate = new Date(startDate);
6363
while (currentDate <= endDate) {
64-
allDateStrings.push(currentDate.toISOString().split("T")[0]);
64+
allDateStrings.push(currentDate.toISOString().split("T")[0]!);
6565
currentDate.setDate(currentDate.getDate() + 1);
6666
}
6767

6868
const tomorrow = new Date(today);
6969
tomorrow.setDate(tomorrow.getDate() + 1);
70-
const tomorrowStr = tomorrow.toISOString().split("T")[0];
70+
const tomorrowStr = tomorrow.toISOString().split("T")[0]!;
7171
if (!allDateStrings.includes(tomorrowStr)) allDateStrings.push(tomorrowStr);
7272

7373
const heartbeatsByDate = new Map<string, any[]>();
7474

7575
for (let i = 0; i < allDateStrings.length; i++) {
76-
const dateStr = allDateStrings[i];
76+
const dateStr = allDateStrings[i]!;
7777

7878
const heartbeatsUrl = `${baseUrl}/users/${userIdentifier}/heartbeats`;
7979
const heartbeatsResponse = await $fetch<{ data: WakApiHeartbeat[] }>(
@@ -171,7 +171,7 @@ export async function handleWakApiSequentialImport(
171171
});
172172

173173
for (let i = 0; i < datesWithData.length; i++) {
174-
const dateStr = datesWithData[i];
174+
const dateStr = datesWithData[i]!;
175175
const heartbeats = heartbeatsByDate.get(dateStr);
176176

177177
if (heartbeats && heartbeats.length > 0) {

server/utils/wakatime.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { handleApiError, handleLog } from "~~/server/utils/logging";
33
import { activeJobs, updateJob } from "~~/server/utils/import-queue";
44
import { randomUUID } from "crypto";
55
import path from "path";
6-
import { ImportJob, ImportStatus } from "~~/types/import";
6+
import { type ImportJob, ImportStatus } from "~~/types/import";
77

88
const enum Endpoints {
99
WakatimeApiUrl = "https://api.wakatime.com/api/v1",
@@ -494,8 +494,8 @@ export function parseUserAgent(userAgent: string): {
494494
const match = userAgent.match(userAgentPattern);
495495

496496
if (match && match.length >= 3) {
497-
let os: string = match[1];
498-
let editor: string = match[2];
497+
let os: string = match[1]!;
498+
let editor: string = match[2]!;
499499

500500
const editorLower = editor.toLowerCase();
501501
editor =
@@ -530,7 +530,7 @@ export function parseUserAgent(userAgent: string): {
530530
editor.replace(/\b\w/g, (l) => l.toUpperCase());
531531

532532
if (osMatch && osMatch[1]) {
533-
const osInfo = osMatch[1].split(";")[0].trim();
533+
const osInfo = osMatch[1]!.split(";")[0]!.trim();
534534
if (osInfo.startsWith("Windows")) {
535535
os = "Windows";
536536
} else if (osInfo.startsWith("Macintosh")) {

0 commit comments

Comments
 (0)