You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I mentioned some problems with typings in this issue: #36
Imagine I have 2 modules:
module1:
and module2 which depends on module1:
Module2AwareState extends Module1AwareState (as in official typescript-example)
and I get this error from ts:
I've also tried to use IModuleTuple interface as a return type of getModule2s function, but in this case I've lost ts benefits
another unclear point. DynamicModuleLoader's modules prop type is array of IModuleTuple:
Does it mean what I aways should wrap getModuleXXX in array when I pass it to DynamicModuleLoader component even if it already returns array of modules like this?
Or maybe something wrong with typings?
Alex Bettadapur (@abettadapur) can you respond to the IModuleTuple part of the question?
Regarding the typing issue with reducer, recently we also experience it and follow this pattern, we should update the example to cover this.
interface IModule1AwareState {
key1: string;
}
interface IModule2OwnState {
key2: string;
}
interface IModule2AwareState extends IModule2OwnState, IModule1AwareState {
}
const _module2: IModule<IModule2OwnState> = {
...
}
// We just use implicit typing for getModule2 method.
function getModule2() {
return [
getModule1(),
_module2
]
}
I've been having trouble with typings: The IModuleTuple problem above and using getState() to return a typed object rather than "any". I'm considering creating a getState<IMyModuleState>()
function that can return the strongly typed module state... is something like this in the works at all?
If anyone has better ideas on ways to implement the typings here, please feel free to let me know, or submit a PR. The main issue I ran into was that it is very difficult to define accurate typings for a dynamic list of items.
The solution we landed on is what Navneet Gupta (@navneet-g) outlined above, which is to define individual modules separately with a type annotation and return an untyped list of modules, which is ducktyped to IModuleTuple. I didn't intend for IModuleTuple to be used explicitly, it is rather a way to define modules as follows
const_module1: IModule<IModule1OwnState> = {...};
const _module2: IModule<IModule2OwnState> = {...};
export const OneAndTwoModule = [_module1, module2];
const _module3: IModule<IModule3OwnState> = {...};// nested arrays, but handled by the library and transparent to you// states that ThreeModule has a dependency on OneAndTwoModule, without directly knowing the exact contents of that moduleexportconstThreeModule=[OneAndTwoModule,_module3];
Does that make sense?
Confusion like this is exactly why I want to add this page. I am drafting it now
Thank you! The solution with *OwnState and AwareState types works in my case.
One part what I don't quite understand is wrapping getModules() function (which returns array of modules) in array like this: <DynamicModuleLoader modules={[get*Modules()]}>...</DynamicModuleLoader>
Сan it affect performance? Because as far as I understand each render call we pass new array as 'modules' prop to DynamicModuleLoader comp.
One more thing. It's very cool that you added a Typescript section to your docs. This section describes Module Dependencies concept which is more general and not directly related to ts. Maybe it would be better to put it in a separate section?
Thanks again!
The confusion I have is in the examples. There is createStore<State> that returns an IModuleStore<State> which I guess helps you ensure modules will conform whatever State is, which I suppose would be the module schema e.g. id, reducerMap, initialActions etc.
Then there's the IModule<State> where State is whatever the reducer for that module returns e.g. IModule<IUserState>.
The problem comes from store.getState() to grab a particular module for testing. And as they're all typed as any in the DynamicModuleLoader, is there any need to strongly type any IModule?
I feel like I'm missing something with regards to implementation.
Btw I wrapped createStore in my own createStore function that has a getModuleById<T>(moduleId:string) function that returns a typed module for testing, other than that I can't see how I could easily integrate this with the rest of the sdk.
Activity
navneet-g commentedon Jan 19, 2019
We have a typescript example, do you plan to further update it?
https://github.com/Microsoft/redux-dynamic-modules/tree/master/packages/typescript-example
abettadapur commentedon Jan 19, 2019
abdurahmanus commentedon Jan 21, 2019
I mentioned some problems with typings in this issue: #36






Imagine I have 2 modules:
module1:
and module2 which depends on module1:
Module2AwareState extends Module1AwareState (as in official typescript-example)
and I get this error from ts:
I've also tried to use IModuleTuple interface as a return type of getModule2s function, but in this case I've lost ts benefits
abdurahmanus commentedon Jan 21, 2019
of course getModule2s from example above should return module with id "module2"
abdurahmanus commentedon Jan 21, 2019
also I could create temp valiable with type IModule, but reducerMap still wants from me reducer for module1 key.

abdurahmanus commentedon Jan 21, 2019
another unclear point. DynamicModuleLoader's modules prop type is array of IModuleTuple:


Does it mean what I aways should wrap getModuleXXX in array when I pass it to DynamicModuleLoader component even if it already returns array of modules like this?
Or maybe something wrong with typings?
navneet-g commentedon Jan 22, 2019
Alex Bettadapur (@abettadapur) can you respond to the IModuleTuple part of the question?
Regarding the typing issue with reducer, recently we also experience it and follow this pattern, we should update the example to cover this.
danrfg commentedon Jan 23, 2019
I've been having trouble with typings: The IModuleTuple problem above and using getState() to return a typed object rather than "any". I'm considering creating a
getState<IMyModuleState>()function that can return the strongly typed module state... is something like this in the works at all?
abettadapur commentedon Jan 24, 2019
If anyone has better ideas on ways to implement the typings here, please feel free to let me know, or submit a PR. The main issue I ran into was that it is very difficult to define accurate typings for a dynamic list of items.
The solution we landed on is what Navneet Gupta (@navneet-g) outlined above, which is to define individual modules separately with a type annotation and return an untyped list of modules, which is ducktyped to
IModuleTuple. I didn't intend forIModuleTupleto be used explicitly, it is rather a way to define modules as followsDoes that make sense?
Confusion like this is exactly why I want to add this page. I am drafting it now
abdurahmanus commentedon Jan 24, 2019
Thank you! The solution with *OwnState and AwareState types works in my case.
One part what I don't quite understand is wrapping getModules() function (which returns array of modules) in array like this:
<DynamicModuleLoader modules={[get*Modules()]}>...</DynamicModuleLoader>Сan it affect performance? Because as far as I understand each render call we pass new array as 'modules' prop to DynamicModuleLoader comp.
One more thing. It's very cool that you added a Typescript section to your docs. This section describes Module Dependencies concept which is more general and not directly related to ts. Maybe it would be better to put it in a separate section?
Thanks again!
danrfg commentedon Jan 24, 2019
The confusion I have is in the examples. There is
createStore<State>that returns anIModuleStore<State>which I guess helps you ensure modules will conform whatever State is, which I suppose would be the module schema e.g. id, reducerMap, initialActions etc.Then there's the
IModule<State>where State is whatever the reducer for that module returns e.g.IModule<IUserState>.The problem comes from store.getState() to grab a particular module for testing. And as they're all typed as
anyin the DynamicModuleLoader, is there any need to strongly type any IModule?I feel like I'm missing something with regards to implementation.
danrfg commentedon Jan 24, 2019
Btw I wrapped createStore in my own createStore function that has a
getModuleById<T>(moduleId:string)function that returns a typed module for testing, other than that I can't see how I could easily integrate this with the rest of the sdk.abettadapur commentedon Jan 28, 2019
abdurahmanus (@abdurahmanus) Good suggestion, I will create another section related to 'dependencies'