Joelgullander
Joelgullander

Reputation: 1684

Returntype of function with input value

So basicly I want to render a returntype for my combined reducers which I do just fine by:

const rootReducer = combineReducers({
  notes: notesReducer,
  categories: categoriesReducer,
  flyout: flyoutReducer
  // more reducers
});

export type AppState = ReturnType<typeof rootReducer>;

However if I were to accept a passed in value to the function I am having issues returning the types correctly. Example below:

const rootReducer = history =>
  combineReducers({
    router: connectRouter(history),
    page: pageReducer,
    ....
    ....

export type AppState = ReturnType<typeof rootReducer>;

How can I invoke the function to get the same returned types??

Upvotes: 0

Views: 40

Answers (1)

Titian Cernicova-Dragomir
Titian Cernicova-Dragomir

Reputation: 249716

You can just use ReturnType twice:

const rootReducer = history =>
    combineReducers({
        router: connectRouter(history),
        page: pageReducer,
    });

export type AppState = ReturnType<ReturnType<typeof rootReducer>>;

Playground Link

Upvotes: 1

Related Questions