diff options
Diffstat (limited to 'src/api/Settings.ts')
-rw-r--r-- | src/api/Settings.ts | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/api/Settings.ts b/src/api/Settings.ts index 2f78668..709050f 100644 --- a/src/api/Settings.ts +++ b/src/api/Settings.ts @@ -254,8 +254,12 @@ export function migratePluginSettings(name: string, ...oldNames: string[]) { } } -export function definePluginSettings<D extends SettingsDefinition, C extends SettingsChecks<D>>(def: D, checks?: C) { - const definedSettings: DefinedSettings<D> = { +export function definePluginSettings< + Def extends SettingsDefinition, + Checks extends SettingsChecks<Def>, + PrivateSettings extends object = {} +>(def: Def, checks?: Checks) { + const definedSettings: DefinedSettings<Def, Checks, PrivateSettings> = { get store() { if (!definedSettings.pluginName) throw new Error("Cannot access settings before plugin is initialized"); return Settings.plugins[definedSettings.pluginName] as any; @@ -264,11 +268,11 @@ export function definePluginSettings<D extends SettingsDefinition, C extends Set settings?.map(name => `plugins.${definedSettings.pluginName}.${name}`) as UseSettings<Settings>[] ).plugins[definedSettings.pluginName] as any, def, - checks: checks ?? {}, + checks: checks ?? {} as any, pluginName: "", - withPrivateSettings<T>() { - return this as DefinedSettings<D, C> & { store: T; }; + withPrivateSettings<T extends object>() { + return this as DefinedSettings<Def, Checks, T>; } }; |