Skip to content

Commit 8775735

Browse files
committed
ts-fix: disambiguate ElectronStore typings
1 parent 7b033b5 commit 8775735

File tree

2 files changed

+42
-42
lines changed

2 files changed

+42
-42
lines changed

src/config/index.ts

+13-15
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import Store from 'electron-store';
21
import { deepmergeCustom } from 'deepmerge-ts';
32

43
import defaultConfig from './defaults';
54

6-
import store from './store';
5+
import store, { IStore } from './store';
76
import plugins from './plugins';
87

98
import { restart } from '@/providers/app-controls';
@@ -62,20 +61,19 @@ type Join<K, P> = K extends string | number
6261
type Paths<T, D extends number = 10> = [D] extends [never]
6362
? never
6463
: T extends object
65-
? {
66-
[K in keyof T]-?: K extends string | number
67-
? `${K}` | Join<K, Paths<T[K], Prev[D]>>
68-
: never;
69-
}[keyof T]
70-
: '';
64+
? {
65+
[K in keyof T]-?: K extends string | number
66+
? `${K}` | Join<K, Paths<T[K], Prev[D]>>
67+
: never;
68+
}[keyof T]
69+
: '';
7170

7271
type SplitKey<K> = K extends `${infer A}.${infer B}` ? [A, B] : [K, string];
73-
type PathValue<T, K extends string> = SplitKey<K> extends [
74-
infer A extends keyof T,
75-
infer B extends string,
76-
]
77-
? PathValue<T[A], B>
78-
: T;
72+
type PathValue<T, K extends string> =
73+
SplitKey<K> extends [infer A extends keyof T, infer B extends string]
74+
? PathValue<T[A], B>
75+
: T;
76+
7977
const get = <Key extends Paths<typeof defaultConfig>>(key: Key) =>
8078
store.get(key) as PathValue<typeof defaultConfig, typeof key>;
8179

@@ -86,7 +84,7 @@ export default {
8684
setPartial,
8785
setMenuOption,
8886
edit: () => store.openInEditor(),
89-
watch(cb: Parameters<Store['onDidAnyChange']>[0]) {
87+
watch(cb: Parameters<IStore['onDidAnyChange']>[0]) {
9088
store.onDidAnyChange(cb);
9189
},
9290
plugins,

src/config/store.ts

+29-27
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import Store from 'electron-store';
2-
import Conf from 'conf';
32

43
import defaults from './defaults';
54

65
import { DefaultPresetList, type Preset } from '@/plugins/downloader/types';
76

7+
// prettier-ignore
8+
export type IStore = InstanceType<typeof import('conf/dist/source/index').default<Record<string, unknown>>>;
9+
810
const migrations = {
9-
'>=3.3.0'(store: Conf<Record<string, unknown>>) {
11+
'>=3.3.0'(store: IStore) {
1012
const lastfmConfig = store.get('plugins.lastfm') as {
1113
enabled?: boolean;
1214
token?: string;
@@ -16,21 +18,21 @@ const migrations = {
1618
secret?: string;
1719
};
1820
if (lastfmConfig) {
19-
let scrobblerConfig = store.get(
20-
'plugins.scrobbler',
21-
) as {
22-
enabled?: boolean;
23-
scrobblers?: {
24-
lastfm?: {
21+
let scrobblerConfig = store.get('plugins.scrobbler') as
22+
| {
2523
enabled?: boolean;
26-
token?: string;
27-
sessionKey?: string;
28-
apiRoot?: string;
29-
apiKey?: string;
30-
secret?: string;
31-
};
32-
};
33-
} | undefined;
24+
scrobblers?: {
25+
lastfm?: {
26+
enabled?: boolean;
27+
token?: string;
28+
sessionKey?: string;
29+
apiRoot?: string;
30+
apiKey?: string;
31+
secret?: string;
32+
};
33+
};
34+
}
35+
| undefined;
3436

3537
if (!scrobblerConfig) {
3638
scrobblerConfig = {
@@ -56,7 +58,7 @@ const migrations = {
5658
store.delete('plugins.lastfm');
5759
}
5860
},
59-
'>=3.0.0'(store: Conf<Record<string, unknown>>) {
61+
'>=3.0.0'(store: IStore) {
6062
const discordConfig = store.get('plugins.discord') as Record<
6163
string,
6264
unknown
@@ -78,14 +80,14 @@ const migrations = {
7880
}
7981
}
8082
},
81-
'>=2.1.3'(store: Conf<Record<string, unknown>>) {
83+
'>=2.1.3'(store: IStore) {
8284
const listenAlong = store.get('plugins.discord.listenAlong');
8385
if (listenAlong !== undefined) {
8486
store.set('plugins.discord.playOnYouTubeMusic', listenAlong);
8587
store.delete('plugins.discord.listenAlong');
8688
}
8789
},
88-
'>=2.1.0'(store: Conf<Record<string, unknown>>) {
90+
'>=2.1.0'(store: IStore) {
8991
const originalPreset = store.get('plugins.downloader.preset') as
9092
| string
9193
| undefined;
@@ -110,7 +112,7 @@ const migrations = {
110112
store.delete('plugins.downloader.ffmpegArgs');
111113
}
112114
},
113-
'>=1.20.0'(store: Conf<Record<string, unknown>>) {
115+
'>=1.20.0'(store: IStore) {
114116
store.delete('plugins.visualizer'); // default value is now in the plugin
115117

116118
if (store.get('plugins.notifications.toastStyle') === undefined) {
@@ -125,14 +127,14 @@ const migrations = {
125127
store.set('options.likeButtons', 'force');
126128
}
127129
},
128-
'>=1.17.0'(store: Conf<Record<string, unknown>>) {
130+
'>=1.17.0'(store: IStore) {
129131
store.delete('plugins.picture-in-picture'); // default value is now in the plugin
130132

131133
if (store.get('plugins.video-toggle.mode') === undefined) {
132134
store.set('plugins.video-toggle.mode', 'custom');
133135
}
134136
},
135-
'>=1.14.0'(store: Conf<Record<string, unknown>>) {
137+
'>=1.14.0'(store: IStore) {
136138
if (
137139
typeof store.get('plugins.precise-volume.globalShortcuts') !== 'object'
138140
) {
@@ -144,12 +146,12 @@ const migrations = {
144146
store.set('plugins.video-toggle.enabled', true);
145147
}
146148
},
147-
'>=1.13.0'(store: Conf<Record<string, unknown>>) {
149+
'>=1.13.0'(store: IStore) {
148150
if (store.get('plugins.discord.listenAlong') === undefined) {
149151
store.set('plugins.discord.listenAlong', true);
150152
}
151153
},
152-
'>=1.12.0'(store: Conf<Record<string, unknown>>) {
154+
'>=1.12.0'(store: IStore) {
153155
const options = store.get('plugins.shortcuts') as
154156
| Record<
155157
string,
@@ -187,12 +189,12 @@ const migrations = {
187189
}
188190
}
189191
},
190-
'>=1.11.0'(store: Conf<Record<string, unknown>>) {
192+
'>=1.11.0'(store: IStore) {
191193
if (store.get('options.resumeOnStart') === undefined) {
192194
store.set('options.resumeOnStart', true);
193195
}
194196
},
195-
'>=1.7.0'(store: Conf<Record<string, unknown>>) {
197+
'>=1.7.0'(store: IStore) {
196198
const enabledPlugins = store.get('plugins') as string[];
197199
if (!Array.isArray(enabledPlugins)) {
198200
console.warn('Plugins are not in array format, cannot migrate');
@@ -233,4 +235,4 @@ export default new Store({
233235
},
234236
clearInvalidConfig: false,
235237
migrations,
236-
});
238+
}) as Store & IStore;

0 commit comments

Comments
 (0)