typescript - 如何为具有接口的数组声明类型?
问题描述
this.bestMatch = listOfFoundedMatches[userWithTheHighestRank];
的回报this.bestMatch
将是:
现在我正在使用private bestMatch;
,但我想定义一个类型声明。而不是any
我可以使用一个界面。我已经尝试过:
export interface Imatch {
email: string;
first_name: string;
last_name: string;
gender: string;
phone: number;
}
export interface Irank {
absolute: string;
relative: number;
}
我真的需要 2 个接口还是只有 1 个?
由于我有0
或在接口之前rank
,data
我不知道如何声明一个类型。你们会怎么做呢?
解决方案
推荐阅读
- javascript - Woocommerce,在产品标题后显示选定的属性标题
- r - 如何在 R ggplot 图中设置 Y 轴的固定宽度?
- java - Spring boot Interface Projection 只返回 null
- java - Hibernate 将 @OneToMany 映射列保存为空值
- vb.net - 文本框选择只工作一半的时间
- python - 如何更改 matplotlib 中网格线的位置?
- ios - 将 CMSampleBuffer 存储在数据结构中导致来自样本缓冲区委托的丢帧
- rpgle - RPGLE 将计数器递增到数据结构中
- python - Python / NumPy 类型提示让我抓狂
- arrays - 带有泛型集合的 Swift 协议