Type Challenges Judge

IndexOf

提出詳細

type IndexOf<T extends unknown[], U, I extends unknown[] = []> = T extends [infer L, ...infer R] ? Equal<L, U> extends true ? I["length"] : IndexOf<R, U, [...I, 0]> : -1
提出日時2023-08-31 17:40:00
問題IndexOf
ユーザーookkoouu
ステータスAccepted
テストケース
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<IndexOf<[1, 2, 3], 2>, 1>>, Expect<Equal<IndexOf<[2, 6, 3, 8, 4, 1, 7, 3, 9], 3>, 2>>, Expect<Equal<IndexOf<[0, 0, 0], 2>, -1>>, Expect<Equal<IndexOf<[string, 1, number, 'a'], number>, 2>>, Expect<Equal<IndexOf<[string, 1, number, 'a', any], any>, 4>>, ]