/*! * @pinia/plugin-debounce v2.0.0 * (c) 2026 Eduardo San Martin Morote * @license MIT */ import { PiniaPluginContext, StoreActions } from "pinia"; //#region src/index.d.ts /** * Accepted interface for the debounce function passed to `PiniaDebounce`. */ interface Debounce { (fn: (...args: any[]) => any, time: number): any; } /** * Adds a `debounce` option to your store to debounce any action. The `debounce` * method can be lodash.debounce, ts-debounce, or any other debounce method. * * @example * * ```ts * import { debounce } from 'ts-debounce' * * // Pass the plugin to your application's pinia plugin * pinia.use(PiniaDebounce(debounce)) * ``` * * @param debounce - debounce method to be invoked */ declare const PiniaDebounce: (debounce: Debounce) => ({ options, store }: PiniaPluginContext) => Record any> | undefined; declare module "pinia" { interface DefineStoreOptionsBase { /** * Debounce any action by a specified amount of time in ms. * * @example * * ```js * defineStore('id', { * actions: { someSearch() {}}, * debounce: { * // debounce all `someSearch` calls by 300ms * someSearch: 300 * } * }) * ``` */ debounce?: Partial, number | (Config extends Record<"Debounce", infer DebounceFn> ? _ParamsAfterNumber : [number, ...any[]])>>; } } type _ParamsAfterNumber = F extends ((fn: (...args: any[]) => any, time: number, ...rest: infer Rest) => any) ? [number, ...Rest] : [number, ...any[]]; /** * Allows you to provide a type for your debounce function so you can pass extra arguments to it in a type safe way. * * @example * * ```ts * // Add this to your main.ts or any other ts file * import { debounce } from 'ts-debounce' * declare module '@pinia/plugin-debounce' { * export interface Config { * Debounce: typeof debounce * } * } * ``` */ interface Config {} //#endregion export { Config, Debounce, PiniaDebounce, _ParamsAfterNumber };