Skip to content

Commit

Permalink
Update type definitions and improve type safety
Browse files Browse the repository at this point in the history
- Add `Timer` type to various timeout variables in `BrtPlayer.vue`, `QImgCustom.ts`, and `notification.ts` for better type safety.
- Update `@types/serviceworker` to version `0.0.95` in `package.json`.
- Include `@types/node` in `tsconfig.json` for enhanced type support.
- Specify `ExtendableEvent` type in `custom-service-worker.ts` for better clarity.
- Cast return value to `ArrayBuffer` in `base64ToArrayBuffer.ts` for type correctness.
  • Loading branch information
tachibana-shin committed Sep 20, 2024
1 parent eaacb68 commit 48f50a9
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 15 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"@types/prompts": "^2.4.4",
"@types/qrcode": "^1.5.1",
"@types/semver": "^7.5.0",
"@types/serviceworker": "^0.0.67",
"@types/serviceworker": "^0.0.95",
"@types/set-cookie-parser": "^2.4.3",
"@types/sha256": "^0.2.0",
"@types/sort-array": "^4.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src-pwa/custom-service-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ declare const self: ServiceWorkerGlobalScope & typeof globalThis
void self.skipWaiting()
clientsClaim()

addEventListener("activate", (event) => {
addEventListener("activate", (event: ExtendableEvent) => {
event.waitUntil(clients.claim())
})

Expand Down
10 changes: 5 additions & 5 deletions src/components/BrtPlayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1720,7 +1720,7 @@ function throttle<T extends (...args: any[]) => Promise<void>>(
} {
let wait = false
let timeout: NodeJS.Timeout | number | undefined
let timeout: NodeJS.Timeout | Timer | number | undefined
// eslint-disable-next-line functional/functional-parameters, @typescript-eslint/no-explicit-any
const cb = function (...args: any[]) {
if (wait === false) {
Expand Down Expand Up @@ -2191,7 +2191,7 @@ function remount(resetCurrentTime?: boolean, noDestroy = false) {
let needSwapCodec = false
let timeoutUnneedSwapCodec: NodeJS.Timeout | number | null = null
let timeoutUnneedSwapCodec: NodeJS.Timeout | Timer | number | null = null
hls.on(Hls.Events.ERROR, (event, data) => {
if (data.fatal) {
console.warn("Player fatal: ", data)
Expand Down Expand Up @@ -2420,7 +2420,7 @@ useEventListener(window, "mouseup", () => {
// ==== addons swipe backdrop ====
let timeoutHoldBD: number | NodeJS.Timeout | null = null
let timeoutHoldBD: number | NodeJS.Timeout | Timer | null = null
const holdedBD = ref(false)
Expand Down Expand Up @@ -2494,13 +2494,13 @@ function skipForward() {
const doubleClicking = ref<"left" | "right" | false>(false)
let timeoutResetDoubleClicking: number | NodeJS.Timeout | null = null
let timeoutResetDoubleClicking: number | NodeJS.Timeout | Timer | null = null
let lastTimeClick: number
let lastPositionClickIsLeft: boolean | null = null
let timeoutDbClick: number | NodeJS.Timeout | null = null
let timeoutDbClick: number | NodeJS.Timeout | Timer | null = null
const countSkip = ref(0)
function onClickSkip(event: MouseEvent) {
if (document.querySelector(".q-menu")) return // prevent if menu showing
Expand Down
11 changes: 6 additions & 5 deletions src/components/QImgCustom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ export default defineComponent({
const naturalRatio = ref(props.initialRatio)
const ratioStyle = useRatio(props, naturalRatio)

let loadTimer: string | number | NodeJS.Timeout | null | undefined = null
let loadTimer: string | number | NodeJS.Timeout | Timer | null | undefined =
null
let isDestroyed = false

const images: Ref<{ src: string } | null>[] = [
Expand Down Expand Up @@ -164,7 +165,7 @@ export default defineComponent({

async function addImage(imgProps: { src: string } | null) {
if (loadTimer !== null) {
clearTimeout(loadTimer)
if (typeof loadTimer === "number") clearTimeout(loadTimer)
loadTimer = null
}

Expand All @@ -189,7 +190,7 @@ export default defineComponent({
}

if (loadTimer !== null) {
clearTimeout(loadTimer)
if (typeof loadTimer === "number") clearTimeout(loadTimer)
loadTimer = null
}

Expand Down Expand Up @@ -243,7 +244,7 @@ export default defineComponent({
// // }
// } catch {
if (loadTimer !== null) {
clearTimeout(loadTimer)
if (typeof loadTimer === "number") clearTimeout(loadTimer)
loadTimer = null
}

Expand Down Expand Up @@ -332,7 +333,7 @@ export default defineComponent({
isDestroyed = true

if (loadTimer !== null) {
clearTimeout(loadTimer)
if (typeof loadTimer === "number") clearTimeout(loadTimer)
loadTimer = null
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/logic/base64ToArrayBuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export function base64ToArrayBuffer(base64: string): ArrayBuffer {
for (let i = 0; i < len; i++) {
bytes[i] = binaryString.charCodeAt(i)
}
return bytes.buffer
return bytes.buffer as ArrayBuffer
}
2 changes: 1 addition & 1 deletion src/stores/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const useNotificationStore = defineStore(

const loading = ref(false)

let timeout: NodeJS.Timeout | number
let timeout: NodeJS.Timeout | Timer | number

let countFail = 0
async function updateNotification() {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"noEmitOnError": false,
/* end */
"baseUrl": "./",
"types": ["vitest/globals", "unplugin-icons/types/vue"],
"types": ["vitest/globals", "unplugin-icons/types/vue", "@types/node"],
"esModuleInterop": true,
"lib": ["esnext", "DOM"]
}
Expand Down

0 comments on commit 48f50a9

Please sign in to comment.