mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-18 04:24:30 +08:00
Improve typing for createStore (review fixes)
This commit is contained in:
17
types/dispatchr/addons/createStore.d.ts
vendored
17
types/dispatchr/addons/createStore.d.ts
vendored
@@ -1,13 +1,20 @@
|
||||
import { StoreClass, Store } from '../index';
|
||||
|
||||
type Diff<T extends string, U extends string> = ({ [P in T]: P } & { [P in U]: never } & { [x: string]: never })[T];
|
||||
type Omit<T, K extends keyof T> = Pick<T, Diff<keyof T, K>>;
|
||||
|
||||
interface StoreOptions {
|
||||
initialize?(): void;
|
||||
storeName: string;
|
||||
handlers: { [event: string]: string };
|
||||
[prop: string]: any;
|
||||
statics?: { [prop: string]: any };
|
||||
mixins?: object[];
|
||||
initialize?(): void;
|
||||
dehydrate?(): any;
|
||||
rehydrate?(state: any): void;
|
||||
}
|
||||
|
||||
type CreateStore = <This extends StoreOptions>(options: This & ThisType<This & Store>) => StoreClass;
|
||||
// see: https://github.com/yahoo/fluxible/blob/dispatchr-v1.2.0/packages/dispatchr/addons/createStore.js#L9
|
||||
type StoreThis<T extends StoreOptions> = Omit<T, 'statics'|'storeName'|'handlers'|'mixins'> & Store
|
||||
|
||||
declare const _: CreateStore;
|
||||
export = _;
|
||||
declare function createStore<T extends StoreOptions>(options: T & ThisType<StoreThis<T>>): StoreClass;
|
||||
export = createStore;
|
||||
|
||||
Reference in New Issue
Block a user