IndexOf
提出詳細
type MyEqual<T,U> = (<X>() => X extends T ? 0 : 1) extends (<X>() => X extends U ? 0 : 1) ? true : false type IndexOf<T, U, Count extends readonly unknown[]=[]> = T extends [infer T1, ...infer T2] ? MyEqual<T1,U> extends true ? Count["length"] : IndexOf<T2,U,[...Count, 0]> : -1
提出日時 | 2023-09-18 07:48:14 |
---|---|
問題 | IndexOf |
ユーザー | sankantsu |
ステータス | 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>>, ]