[Typescript] 107. Medium - FindIndex

Similar to Array.findIndex:

type FindIndex<T extends readonly any[], K, ACC extends unknown[] = []> = T extends readonly [infer F, ...infer RT]
  ? K extends F
    ? ACC['length']
    : FindIndex<RT, K, [...ACC, unknown]>
  : -1;

 

posted @ 2022-11-16 22:34  Zhentiw  阅读(28)  评论(0编辑  收藏  举报