首页 > 解决方案 > 如何为具有接口的数组声明类型?

问题描述

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或在接口之前rankdata我不知道如何声明一个类型。你们会怎么做呢?

标签: typescripttypesinterface

解决方案


推荐阅读