Skip to content

Commit ff147c2

Browse files
committed
adding types order, moved types to package
1 parent bc6a297 commit ff147c2

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
}
5252
]
5353
},
54-
"types": "dist/index.d.ts",
54+
"types": "package/index.d.ts",
5555
"scripts": {
5656
"lint": "eslint ./package ./tests",
5757
"format": "eslint --fix ./package ./tests ./examples",

package/index.d.ts

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
declare module "teaful" {
2+
3+
import React from "react";
4+
5+
type HookReturn<T> = [T, (value: T) => void, () => void];
6+
type initialStoreType = Record<string, any>;
7+
8+
type Hook<S> = (
9+
initial?: S,
10+
onAfterUpdate?: afterCallbackType<S>
11+
) => HookReturn<S>;
12+
13+
type HookDry<S> = (initial?: S) => HookReturn<S>;
14+
15+
export type Hoc<S> = { store: HookReturn<S> };
16+
17+
type HocFunc<S, R extends React.ComponentClass = React.ComponentClass> = (
18+
component: R,
19+
initial?: S
20+
) => R;
21+
22+
type afterCallbackType<S extends initialStoreType> = (param: {
23+
store: S;
24+
prevStore: S;
25+
}) => void;
26+
27+
type getStoreType<S extends initialStoreType> = {
28+
[key in keyof S]: S[key] extends initialStoreType
29+
? useStoreType<S[key]> & HookDry<S[key]> : HookDry<S[key]>;
30+
};
31+
32+
type useStoreType<S extends initialStoreType> = {
33+
[key in keyof S]: S[key] extends initialStoreType
34+
? useStoreType<S[key]> & Hook<S[key]> : Hook<S[key]>;
35+
};
36+
37+
type withStoreType<S extends initialStoreType> = {
38+
[key in keyof S]: S[key] extends initialStoreType
39+
? withStoreType<S[key]> & HocFunc<S>
40+
: HocFunc<S>;
41+
};
42+
43+
function createStore<S extends initialStoreType>(
44+
initial: S,
45+
afterCallback?: afterCallbackType<S>
46+
): {
47+
getStore: HookDry<S> & getStoreType<S>;
48+
useStore: Hook<S> & useStoreType<S>;
49+
withStore: HocFunc<S> & withStoreType<S>;
50+
};
51+
52+
export default createStore;
53+
}

0 commit comments

Comments
 (0)