如何解释这些 TypeScript 声明中的 [p in keyof T] 和 T[p]? [英] How to interpret [p in keyof T] and T[p] in these TypeScript declarations?
本文介绍了如何解释这些 TypeScript 声明中的 [p in keyof T] 和 T[p]?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在阅读 ngrx 文档并偶然发现了这样的代码.[p in keyof T]
和 T[p]
是什么意思?
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>
};
推荐答案
That is a mapped type. You can read about them in the typescript docs here, or in this blog post.
基本上,语法 [p in keyof T]
就是这个意思;p
是对象T
的键之一.然后,T[p]
只表示该键值的类型.阅读这两个链接以获得更可靠的解释.
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.
这篇关于如何解释这些 TypeScript 声明中的 [p in keyof T] 和 T[p]?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文