Export types needed for defining custom stores

I wrote a custom store to have a more flexible `derived` store. The function signatures looks like:

```typescript
export function derivedWritable<S extends Stores, T>(
  stores: S,
  fn: (values: StoresValues<S>, set: (value: T) => void) => Unsubscriber | void,
  initial_value?: T
): Writable<T> { ... }
```

Both `Stores` and `StoresValues` are not exported in `svelte/store`. I had to copy paste the type definition from this file and duplicate code. Unless I'm using TypeScript wrong (I'm still quite new to it), I think these types plus few others should be exported.
pull/7358/head
vrde 5 years ago committed by GitHub
parent 2f71bc9333
commit 5a0fb7ddae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -10,7 +10,7 @@ export type Unsubscriber = () => void;
export type Updater<T> = (value: T) => T; export type Updater<T> = (value: T) => T;
/** Cleanup logic callback. */ /** Cleanup logic callback. */
type Invalidator<T> = (value?: T) => void; export type Invalidator<T> = (value?: T) => void;
/** Start and stop notification callbacks. */ /** Start and stop notification callbacks. */
export type StartStopNotifier<T> = (set: Subscriber<T>) => Unsubscriber | void; export type StartStopNotifier<T> = (set: Subscriber<T>) => Unsubscriber | void;
@ -41,7 +41,7 @@ export interface Writable<T> extends Readable<T> {
} }
/** Pair of subscriber and invalidator. */ /** Pair of subscriber and invalidator. */
type SubscribeInvalidateTuple<T> = [Subscriber<T>, Invalidator<T>]; export type SubscribeInvalidateTuple<T> = [Subscriber<T>, Invalidator<T>];
const subscriber_queue = []; const subscriber_queue = [];
@ -109,10 +109,10 @@ export function writable<T>(value?: T, start: StartStopNotifier<T> = noop): Writ
} }
/** One or more `Readable`s. */ /** One or more `Readable`s. */
type Stores = Readable<any> | [Readable<any>, ...Array<Readable<any>>] | Array<Readable<any>>; export type Stores = Readable<any> | [Readable<any>, ...Array<Readable<any>>] | Array<Readable<any>>;
/** One or more values from `Readable` stores. */ /** One or more values from `Readable` stores. */
type StoresValues<T> = T extends Readable<infer U> ? U : export type StoresValues<T> = T extends Readable<infer U> ? U :
{ [K in keyof T]: T[K] extends Readable<infer U> ? U : never }; { [K in keyof T]: T[K] extends Readable<infer U> ? U : never };
/** /**

Loading…
Cancel
Save