fix(types): some errors

Signed-off-by: Fernando Fernández <ferferga@hotmail.com>
This commit is contained in:
Fernando Fernández 2024-09-06 22:40:37 +02:00
parent ccded13292
commit 8984a2d639
No known key found for this signature in database
GPG Key ID: 82FD36644F1F4D3B
3 changed files with 17 additions and 5 deletions

View File

@ -35,7 +35,7 @@ import playbackProfile from '@/utils/playback-profiles';
import { msToTicks } from '@/utils/time';
import { mediaControls, mediaElementRef } from '@/store';
import { CommonStore } from '@/store/super/common-store';
import { genericWorker } from '@/plugins/workers';
import { shuffle } from '@/utils/data-manipulation';
/**
* == INTERFACES AND TYPES ==
@ -173,7 +173,7 @@ class PlaybackManagerStore extends CommonStore<PlaybackManagerState> {
* Get reactive BaseItemDto's objects of the queue
*/
public get queue(): BaseItemDto[] {
return apiStore.getItemsById(this._state.queue) as BaseItemDto[] ?? [];
return apiStore.getItemsById(this._state.queue) as BaseItemDto[];
}
/**
@ -776,7 +776,7 @@ class PlaybackManagerStore extends CommonStore<PlaybackManagerState> {
this._state.originalQueue = [];
this._state.isShuffling = false;
} else {
const queue = await genericWorker.shuffle(toRaw(this._state.queue));
const queue = await shuffle(this._state.queue);
this._state.originalQueue = this._state.queue;

View File

@ -1,4 +1,6 @@
import { defu } from 'defu';
import { toRaw } from 'vue';
import { genericWorker } from '@/plugins/workers';
/**
* Merge 2 objects, excluding the keys from the destination that are not present in source
@ -68,3 +70,13 @@ export function pick<T extends object>(object: T, keys: (keyof T)[]): Partial<T>
return res;
}
/**
* Shuffles an array in a WebWorker using the Durstenfeld shuffle algorithm, an
* optimized version of Fisher-Yates shuffle.
*
* It's also prepared for the case when the array is reactive thorugh Vue's `ref` or `reactive`.
*/
export async function shuffle<T>(array: T[]): Promise<T[]> {
return await genericWorker.shuffle(toRaw(array)) as T[];
}

View File

@ -31,7 +31,7 @@ export function isStr(value: unknown): value is string {
/**
* Check if the given value is a funcion
*/
export function isFunc<T extends (...args: unknown[]) => unknown>(value: unknown): value is T {
export function isFunc(value: unknown): value is (...args: unknown[]) => unknown {
return typeof value === 'function';
}
@ -82,7 +82,7 @@ export function isArray(object: unknown): object is unknown[] {
*
* @type TypeScript Decorator
*/
export function sealed<T extends new(...args: unknown[]) => unknown>(constructor: T): void {
export function sealed(constructor: new (...args: never[]) => object): void {
Object.seal(constructor);
Object.seal(constructor.prototype);
}