diff --git a/src/api/Settings.ts b/src/api/Settings.ts index 2f786681..709050f5 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>(def: D, checks?: C) { - const definedSettings: DefinedSettings = { +export function definePluginSettings< + Def extends SettingsDefinition, + Checks extends SettingsChecks, + PrivateSettings extends object = {} +>(def: Def, checks?: Checks) { + const definedSettings: DefinedSettings = { 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 `plugins.${definedSettings.pluginName}.${name}`) as UseSettings[] ).plugins[definedSettings.pluginName] as any, def, - checks: checks ?? {}, + checks: checks ?? {} as any, pluginName: "", - withPrivateSettings() { - return this as DefinedSettings & { store: T; }; + withPrivateSettings() { + return this as DefinedSettings; } }; diff --git a/src/utils/types.ts b/src/utils/types.ts index 6af1bdc8..7b682e9b 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -260,25 +260,29 @@ type SettingsStore = { }; /** An instance of defined plugin settings */ -export interface DefinedSettings = {}> { +export interface DefinedSettings< + Def extends SettingsDefinition = SettingsDefinition, + Checks extends SettingsChecks = {}, + PrivateSettings extends object = {} +> { /** Shorthand for `Vencord.Settings.plugins.PluginName`, but with typings */ - store: SettingsStore; + store: SettingsStore & PrivateSettings; /** * React hook for getting the settings for this plugin * @param filter optional filter to avoid rerenders for irrelavent settings */ - use>(filter?: F[]): Pick, F>; + use>(filter?: F[]): Pick & PrivateSettings, F>; /** Definitions of each setting */ - def: D; + def: Def; /** Setting methods with return values that could rely on other settings */ - checks: C; + checks: Checks; /** * Name of the plugin these settings belong to, * will be an empty string until plugin is initialized */ pluginName: string; - withPrivateSettings(): this & { store: T; }; + withPrivateSettings(): DefinedSettings; } export type PartialExcept = Partial & Required>;