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 have some Redux wrapper written in regular JS. This is a factory function that receives the base Redux's createStore and returns async store creator - function returning a promise to be resolved to createStore substitute (that uses real createStore under the hood). I'd like to make Typescript declaration for this wrapper. I already written declaration of the factory function using StoreCreator interface from the Redux typings:
import {
StoreCreator,
} from 'redux';
function factory(obj: {
createStore: StoreCreator,
otherParams: ...,
}): AsyncStoreCreator;
But I'm not sure how to declare AsyncStoreCreator interface.
Can I use the same Redux's StoreCreator interface as a sample? I've tried to copy-paste the respective code from the Redux repo and wrap the return type with Promise. Below is how it looks:
import {
Action,
Reducer,
Store,
PreloadedState,
StoreCreator,
StoreEnhancer,
} from 'redux';
type ExtendState<State, Extension> = [Extension] extends [never]
? State
: State & Extension;
interface AsyncStoreCreator {
<S, A extends Action, Ext = {}, StateExt = never>(
reducer: Reducer<S, A>,
enhancer?: StoreEnhancer<Ext, StateExt>
): Promise<Store<ExtendState<S, StateExt>, A, StateExt, Ext> & Ext>
<S, A extends Action, Ext = {}, StateExt = never>(
reducer: Reducer<S, A>,
preloadedState?: PreloadedState<S>,
enhancer?: StoreEnhancer<Ext>
): Promise<Store<ExtendState<S, StateExt>, A, StateExt, Ext> & Ext>
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have some Redux wrapper written in regular JS. This is a factory function that receives the base Redux's
createStore
and returns async store creator - function returning a promise to be resolved tocreateStore
substitute (that uses realcreateStore
under the hood). I'd like to make Typescript declaration for this wrapper. I already written declaration of the factory function usingStoreCreator
interface from the Redux typings:But I'm not sure how to declare
AsyncStoreCreator
interface.Can I use the same Redux's
StoreCreator
interface as a sample? I've tried to copy-paste the respective code from the Redux repo and wrap the return type with Promise. Below is how it looks:But I'm not sure if this is right way.
Beta Was this translation helpful? Give feedback.
All reactions