From 62c067c1a0a39d3f202cd3d40d57bc34b482a802 Mon Sep 17 00:00:00 2001 From: SegaraRai Date: Tue, 16 Jul 2024 23:00:46 +0900 Subject: [PATCH] fix: fix type error --- app/components/NatureApplianceControlAC.vue | 4 ++-- app/components/ThemeSelector.vue | 4 ++-- nitroSWPreset.ts | 2 +- server/utils/natureAPICache.ts | 2 +- server/utils/serial.test.ts | 22 ++++++++++----------- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/app/components/NatureApplianceControlAC.vue b/app/components/NatureApplianceControlAC.vue index 98dcb86..2eaa6d2 100644 --- a/app/components/NatureApplianceControlAC.vue +++ b/app/components/NatureApplianceControlAC.vue @@ -401,7 +401,7 @@ const getSwipeByData = (offset: SwipeByOffset): SwipeByData | null => { availableTemperatures.length - 1 ); - const newTemperature = availableTemperatures[index]; + const newTemperature = availableTemperatures[index]!; const diff10 = Math.round( Number(newTemperature) * 10 - Number(currentTemperature) * 10 ); @@ -454,7 +454,7 @@ const swipingTemperature = computed((): NatureApplianceACTemperature | null => { Math.max(currentIndex + offset, 0), availableTemperatures.length - 1 ); - return availableTemperatures[index]; + return availableTemperatures[index]!; }); /** diff --git a/app/components/ThemeSelector.vue b/app/components/ThemeSelector.vue index e9bea68..c4d630e 100644 --- a/app/components/ThemeSelector.vue +++ b/app/components/ThemeSelector.vue @@ -63,7 +63,7 @@ const items = computed(() => [ const current = computed( () => items.value.find((item) => item.value === colorMode.preference) ?? - items.value[0] + items.value[0]! ); const toggle = (): void => { @@ -71,6 +71,6 @@ const toggle = (): void => { (item) => item.value === colorMode.preference ); colorMode.preference = - items.value[(currentIndex + 1) % items.value.length].value; + items.value[(currentIndex + 1) % items.value.length]!.value; }; diff --git a/nitroSWPreset.ts b/nitroSWPreset.ts index 9e6b563..ecbfdcf 100644 --- a/nitroSWPreset.ts +++ b/nitroSWPreset.ts @@ -134,7 +134,7 @@ const collectHashes = async (nitro: object, html: string): Promise => { } for (const match of html.matchAll(/]*)>([\s\S]*?)<\/script>/g)) { - if (!match[2] || match[1].includes("application/json")) { + if (!match[2] || match[1]!.includes("application/json")) { continue; } diff --git a/server/utils/natureAPICache.ts b/server/utils/natureAPICache.ts index c11cc73..dfecd95 100644 --- a/server/utils/natureAPICache.ts +++ b/server/utils/natureAPICache.ts @@ -99,7 +99,7 @@ export const natureAPICache = new LRUCache({ { signal, context: { timestamp, token, waitUntil } } ): Promise => { try { - const [userId, method, url] = key.split("\0"); + const [userId, method, url] = key.split("\0") as [string, string, string]; const res = await fetch(url, { method, headers: createNatureAPIRequestHeaderInit(token), diff --git a/server/utils/serial.test.ts b/server/utils/serial.test.ts index 8cc3e82..8018246 100644 --- a/server/utils/serial.test.ts +++ b/server/utils/serial.test.ts @@ -10,7 +10,7 @@ function createPromise(): [Promise, () => void] { } test("should return function that executes specified function", () => { - const fn = vi.fn<[], Promise>().mockResolvedValue(undefined); + const fn = vi.fn<() => Promise>().mockResolvedValue(undefined); const serial = createSerial(fn); expectTypeOf(serial).toBeFunction(); serial(); @@ -31,18 +31,18 @@ test("should not call next one until running one finishes", async () => { }); expect(resolves).toHaveLength(1); - expect(promises[0][1]).not.toHaveBeenCalled(); - expect(promises[1][1]).not.toHaveBeenCalled(); - resolves[0](); - await promises[0][0]; - expect(promises[0][1]).toHaveBeenCalled(); - expect(promises[1][1]).not.toHaveBeenCalled(); + expect(promises[0]![1]).not.toHaveBeenCalled(); + expect(promises[1]![1]).not.toHaveBeenCalled(); + resolves[0]!(); + await promises[0]![0]; + expect(promises[0]![1]).toHaveBeenCalled(); + expect(promises[1]![1]).not.toHaveBeenCalled(); expect(resolves).toHaveLength(2); - resolves[1](); - await promises[1][0]; - expect(promises[1][1]).toHaveBeenCalled(); - expect(promises[19][1]).toHaveBeenCalled(); + resolves[1]!(); + await promises[1]![0]; + expect(promises[1]![1]).toHaveBeenCalled(); + expect(promises[19]![1]).toHaveBeenCalled(); expect(resolves).toHaveLength(2); });