Typescript 如何覆盖索引签名

Typescript 如何覆盖索引签名,typescript,Typescript,如何创建具有不同索引签名的数组导数 比如说 interface SaferArray<T> extends Array<T> { [i: number]: T | undefined } 我将使用类型别名执行此操作: type SaferArray<T> = Array<T | undefined>; const example: SaferArray<string> = ["hello"]; const a = exampl

如何创建具有不同索引签名的
数组
导数

比如说

interface SaferArray<T> extends Array<T> {
  [i: number]: T | undefined
}

我将使用类型别名执行此操作:

type SaferArray<T> = Array<T | undefined>;

const example: SaferArray<string> = ["hello"];

const a = example[0]; // string | undefined
const b = example[1]; // string | undefined
type SaferArray<T> = Array<T | undefined>;

const example: SaferArray<string> = ["hello"];

const a = example[0]; // string | undefined
const b = example[1]; // string | undefined
interface SaferArray<T> extends Array<T | undefined> {
  [i: number]: T | undefined
}