This repository was archived by the owner on Dec 29, 2022. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,22 +8,29 @@ import React, {
88 Context
99} from "react" ;
1010
11- export const createRexStore : < T extends { [ key : string ] : Rex < any > } > (
11+ export const createRexStore : < T extends { [ key : string ] : new ( ) => Rex < any > } > (
1212 store : T
1313) => {
1414 RexProvider : ( { children } : { children : React . ReactNode } ) => JSX . Element ;
15- useRex : ( ) => T ;
15+ useRex : ( ) => {
16+ [ K in keyof typeof store ] : InstanceType < typeof store [ K ] > ;
17+ } ;
1618} = store => {
17- let RexContext : Context < typeof store > ;
19+ type RexStore = {
20+ [ K in keyof typeof store ] : InstanceType < typeof store [ K ] > ;
21+ } ;
22+
23+ let RexContext : Context < RexStore > ;
1824
1925 const useRex = ( ) => {
2026 const store = useContext ( RexContext ) ;
2127 return store ;
2228 } ;
2329
2430 const RexProvider = ( { children } : { children : ReactNode } ) => {
25- const intializedStore : typeof store = { } ;
31+ const intializedStore = { } as RexStore ;
2632 for ( const item in store ) {
33+ // @ts -ignore
2734 intializedStore [ item ] = new store [ item ] ( ) ;
2835 }
2936 RexContext = createContext ( intializedStore ) ;
@@ -48,6 +55,7 @@ class Rex<S> {
4855
4956 public setState < K extends keyof S > ( newInternalState : Pick < S , K > | S ) : void {
5057 if ( ! this . internalState ) {
58+ // @ts -ignore
5159 this . state = newInternalState ;
5260 } else {
5361 this . updateInternalState ( {
You can’t perform that action at this time.
0 commit comments