9286 - FirstUniqueCharIndex
sunupupup opened this issue · comments
sunupupup commented
key point is find the ${Head}${Tail}
extends ${any}${Char}${any}
Head + Char + Tail = T
type FirstUniqueCharIndex<
T extends string,
Head extends string = '',
Count extends any[] = []
> = T extends `${infer Char}${infer Tail}`
? `${Head}${Tail}` extends `${any}${Char}${any}`
? FirstUniqueCharIndex<Tail, `${Head}${Char}`, [...Count, 1]>
: Count['length']
: -1;