74. 实现 IndexOf

中等0

在类型系统中实现一个 IndexOf<T, U> 类型,它的行为类似于 JavaScript 中的 Array.indexOf 方法,该方法接受一个数组 T 和一个元素 U,并返回 U 在数组 T 中第一次出现的索引。

例如:

type Res1 = IndexOf<[1, 2, 3], 2>; // expected to be 1
type Res2 = IndexOf<[2, 6, 3, 8, 4, 1, 7, 3, 9], 3>; // expected to be 2
type Res3 = IndexOf<[0, 0, 0], 2>; // expected to be -1
评论(0)
题库

TypeScript

加载中...