From 877573532c1b68af861a3fdc44d093f3097d36ab Mon Sep 17 00:00:00 2001 From: Angelos Bouklis <53124886+ArjixWasTaken@users.noreply.github.com> Date: Thu, 1 Aug 2024 10:10:52 +0300 Subject: [PATCH] ts-fix: disambiguate ElectronStore typings --- src/config/index.ts | 28 +++++++++++------------ src/config/store.ts | 56 +++++++++++++++++++++++---------------------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/config/index.ts b/src/config/index.ts index 7b1d91ac83..a127eab273 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -1,9 +1,8 @@ -import Store from 'electron-store'; import { deepmergeCustom } from 'deepmerge-ts'; import defaultConfig from './defaults'; -import store from './store'; +import store, { IStore } from './store'; import plugins from './plugins'; import { restart } from '@/providers/app-controls'; @@ -62,20 +61,19 @@ type Join = K extends string | number type Paths = [D] extends [never] ? never : T extends object - ? { - [K in keyof T]-?: K extends string | number - ? `${K}` | Join> - : never; - }[keyof T] - : ''; + ? { + [K in keyof T]-?: K extends string | number + ? `${K}` | Join> + : never; + }[keyof T] + : ''; type SplitKey = K extends `${infer A}.${infer B}` ? [A, B] : [K, string]; -type PathValue = SplitKey extends [ - infer A extends keyof T, - infer B extends string, -] - ? PathValue - : T; +type PathValue = + SplitKey extends [infer A extends keyof T, infer B extends string] + ? PathValue + : T; + const get = >(key: Key) => store.get(key) as PathValue; @@ -86,7 +84,7 @@ export default { setPartial, setMenuOption, edit: () => store.openInEditor(), - watch(cb: Parameters[0]) { + watch(cb: Parameters[0]) { store.onDidAnyChange(cb); }, plugins, diff --git a/src/config/store.ts b/src/config/store.ts index dd6e9ec6cf..01df655b9f 100644 --- a/src/config/store.ts +++ b/src/config/store.ts @@ -1,12 +1,14 @@ import Store from 'electron-store'; -import Conf from 'conf'; import defaults from './defaults'; import { DefaultPresetList, type Preset } from '@/plugins/downloader/types'; +// prettier-ignore +export type IStore = InstanceType>>; + const migrations = { - '>=3.3.0'(store: Conf>) { + '>=3.3.0'(store: IStore) { const lastfmConfig = store.get('plugins.lastfm') as { enabled?: boolean; token?: string; @@ -16,21 +18,21 @@ const migrations = { secret?: string; }; if (lastfmConfig) { - let scrobblerConfig = store.get( - 'plugins.scrobbler', - ) as { - enabled?: boolean; - scrobblers?: { - lastfm?: { + let scrobblerConfig = store.get('plugins.scrobbler') as + | { enabled?: boolean; - token?: string; - sessionKey?: string; - apiRoot?: string; - apiKey?: string; - secret?: string; - }; - }; - } | undefined; + scrobblers?: { + lastfm?: { + enabled?: boolean; + token?: string; + sessionKey?: string; + apiRoot?: string; + apiKey?: string; + secret?: string; + }; + }; + } + | undefined; if (!scrobblerConfig) { scrobblerConfig = { @@ -56,7 +58,7 @@ const migrations = { store.delete('plugins.lastfm'); } }, - '>=3.0.0'(store: Conf>) { + '>=3.0.0'(store: IStore) { const discordConfig = store.get('plugins.discord') as Record< string, unknown @@ -78,14 +80,14 @@ const migrations = { } } }, - '>=2.1.3'(store: Conf>) { + '>=2.1.3'(store: IStore) { const listenAlong = store.get('plugins.discord.listenAlong'); if (listenAlong !== undefined) { store.set('plugins.discord.playOnYouTubeMusic', listenAlong); store.delete('plugins.discord.listenAlong'); } }, - '>=2.1.0'(store: Conf>) { + '>=2.1.0'(store: IStore) { const originalPreset = store.get('plugins.downloader.preset') as | string | undefined; @@ -110,7 +112,7 @@ const migrations = { store.delete('plugins.downloader.ffmpegArgs'); } }, - '>=1.20.0'(store: Conf>) { + '>=1.20.0'(store: IStore) { store.delete('plugins.visualizer'); // default value is now in the plugin if (store.get('plugins.notifications.toastStyle') === undefined) { @@ -125,14 +127,14 @@ const migrations = { store.set('options.likeButtons', 'force'); } }, - '>=1.17.0'(store: Conf>) { + '>=1.17.0'(store: IStore) { store.delete('plugins.picture-in-picture'); // default value is now in the plugin if (store.get('plugins.video-toggle.mode') === undefined) { store.set('plugins.video-toggle.mode', 'custom'); } }, - '>=1.14.0'(store: Conf>) { + '>=1.14.0'(store: IStore) { if ( typeof store.get('plugins.precise-volume.globalShortcuts') !== 'object' ) { @@ -144,12 +146,12 @@ const migrations = { store.set('plugins.video-toggle.enabled', true); } }, - '>=1.13.0'(store: Conf>) { + '>=1.13.0'(store: IStore) { if (store.get('plugins.discord.listenAlong') === undefined) { store.set('plugins.discord.listenAlong', true); } }, - '>=1.12.0'(store: Conf>) { + '>=1.12.0'(store: IStore) { const options = store.get('plugins.shortcuts') as | Record< string, @@ -187,12 +189,12 @@ const migrations = { } } }, - '>=1.11.0'(store: Conf>) { + '>=1.11.0'(store: IStore) { if (store.get('options.resumeOnStart') === undefined) { store.set('options.resumeOnStart', true); } }, - '>=1.7.0'(store: Conf>) { + '>=1.7.0'(store: IStore) { const enabledPlugins = store.get('plugins') as string[]; if (!Array.isArray(enabledPlugins)) { console.warn('Plugins are not in array format, cannot migrate'); @@ -233,4 +235,4 @@ export default new Store({ }, clearInvalidConfig: false, migrations, -}); +}) as Store & IStore;