diff --git a/packages/svelte/src/store/index.js b/packages/svelte/src/store/index.js index b90ebb4de9..393144cff0 100644 --- a/packages/svelte/src/store/index.js +++ b/packages/svelte/src/store/index.js @@ -1,5 +1,5 @@ /** @import { Readable, StartStopNotifier, Subscriber, Unsubscriber, Updater, Writable } from './public' */ -/** @import { Invalidator, Stores, StoresValues, SubscribeInvalidateTuple } from './private' */ +/** @import { Stores, StoresValues, SubscribeInvalidateTuple } from './private' */ import { noop, run_all } from '../internal/shared/utils.js'; import { safe_not_equal } from '../internal/client/reactivity/equality.js'; import { subscribe_to_store } from './utils.js'; @@ -74,7 +74,7 @@ export function writable(value, start = noop) { /** * @param {Subscriber} run - * @param {Invalidator} [invalidate] + * @param {() => void} [invalidate] * @returns {Unsubscriber} */ function subscribe(run, invalidate = noop) { diff --git a/packages/svelte/src/store/private.d.ts b/packages/svelte/src/store/private.d.ts index dd95520b29..5b41c8bd4b 100644 --- a/packages/svelte/src/store/private.d.ts +++ b/packages/svelte/src/store/private.d.ts @@ -1,10 +1,7 @@ import { Readable, Subscriber } from './public.js'; -/** Cleanup logic callback. */ -type Invalidator = (value?: T) => void; - /** Pair of subscriber and invalidator. */ -type SubscribeInvalidateTuple = [Subscriber, Invalidator]; +type SubscribeInvalidateTuple = [Subscriber, () => void]; /** One or more `Readable`s. */ type Stores = Readable | [Readable, ...Array>] | Array>; @@ -13,4 +10,4 @@ type Stores = Readable | [Readable, ...Array>] | Array = T extends Readable ? U : { [K in keyof T]: T[K] extends Readable ? U : never }; -export { Invalidator, SubscribeInvalidateTuple, Stores, StoresValues }; +export { SubscribeInvalidateTuple, Stores, StoresValues }; diff --git a/packages/svelte/src/store/public.d.ts b/packages/svelte/src/store/public.d.ts index 225b3feb68..63cb6bfc4c 100644 --- a/packages/svelte/src/store/public.d.ts +++ b/packages/svelte/src/store/public.d.ts @@ -1,5 +1,3 @@ -import type { Invalidator } from './private.js'; - /** Callback to inform of a value updates. */ type Subscriber = (value: T) => void; @@ -30,7 +28,7 @@ interface Readable { * @param run subscription callback * @param invalidate cleanup callback */ - subscribe(this: void, run: Subscriber, invalidate?: Invalidator): Unsubscriber; + subscribe(this: void, run: Subscriber, invalidate?: () => void): Unsubscriber; } /** Writable interface for both updating and subscribing. */ diff --git a/packages/svelte/types/index.d.ts b/packages/svelte/types/index.d.ts index c63e6366ba..5055799a9d 100644 --- a/packages/svelte/types/index.d.ts +++ b/packages/svelte/types/index.d.ts @@ -2075,7 +2075,7 @@ declare module 'svelte/motion' { * @param run subscription callback * @param invalidate cleanup callback */ - subscribe(this: void, run: Subscriber, invalidate?: Invalidator): Unsubscriber; + subscribe(this: void, run: Subscriber, invalidate?: () => void): Unsubscriber; } interface SpringOpts { stiffness?: number; @@ -2096,8 +2096,6 @@ declare module 'svelte/motion' { easing?: (t: number) => number; interpolate?: (a: T, b: T) => (t: number) => T; } - /** Cleanup logic callback. */ - type Invalidator = (value?: T) => void; /** * The spring function in Svelte creates a store whose value is animated, with a motion that simulates the behavior of a spring. This means when the value changes, instead of transitioning at a steady rate, it "bounces" like a spring would, depending on the physics parameters provided. This adds a level of realism to the transitions and can enhance the user experience. * @@ -2221,7 +2219,7 @@ declare module 'svelte/store' { * @param run subscription callback * @param invalidate cleanup callback */ - subscribe(this: void, run: Subscriber, invalidate?: Invalidator): Unsubscriber; + subscribe(this: void, run: Subscriber, invalidate?: () => void): Unsubscriber; } /** Writable interface for both updating and subscribing. */ @@ -2238,15 +2236,6 @@ declare module 'svelte/store' { */ update(this: void, updater: Updater): void; } - /** Cleanup logic callback. */ - type Invalidator = (value?: T) => void; - - /** One or more `Readable`s. */ - type Stores = Readable | [Readable, ...Array>] | Array>; - - /** One or more values from `Readable` stores. */ - type StoresValues = - T extends Readable ? U : { [K in keyof T]: T[K] extends Readable ? U : never }; /** * Creates a `Readable` store that allows reading by subscription. * @@ -2288,6 +2277,12 @@ declare module 'svelte/store' { * https://svelte.dev/docs/svelte-store#get * */ export function get(store: Readable): T; + /** One or more `Readable`s. */ + type Stores = Readable | [Readable, ...Array>] | Array>; + + /** One or more values from `Readable` stores. */ + type StoresValues = + T extends Readable ? U : { [K in keyof T]: T[K] extends Readable ? U : never }; export { Subscriber, Unsubscriber, Updater, StartStopNotifier, Readable, Writable }; }