函数的返回类型与输入值。

huangapple go评论88阅读模式
英文:

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;

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;

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

英文:

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??

答案1

得分: 1

You can just use ReturnType twice:

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

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

Playground Link

英文:

You can just use ReturnType twice:

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

export type AppState = ReturnType&lt;ReturnType&lt;typeof rootReducer&gt;&gt;;

Playground Link

huangapple
  • 本文由 发表于 2020年1月3日 17:45:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/59576258.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定