How to interpret [p in keyof T] and T[p] in these TypeScript declarations?

你说的曾经没有我的故事 提交于 2020-12-10 16:06:25

问题


I am reading ngrx docs and stumbled upon such a code. What do [p in keyof T] and T[p] mean?

export type ActionReducerMap<T, V extends Action = Action> = {
  [p in keyof T]: ActionReducer<T[p], V>
};

回答1:


That is a mapped type. You can read about them in the typescript docs here, or in this blog post.

Basically, the syntax [p in keyof T] means just that; p is one of the keys of the object T. Then, the T[p] just represents the type of that key's value. Read those two links for a more robust explanation.



来源:https://stackoverflow.com/questions/46856156/how-to-interpret-p-in-keyof-t-and-tp-in-these-typescript-declarations

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!