问题
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