Improve typing for createStore (review fixes)

This commit is contained in:
Ragg
2018-03-01 00:23:53 +09:00
parent 99a18f0113
commit 01aa7a6ff4

View File

@@ -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;