Length of String
提出詳細
type LengthOfString<T extends string, Length extends string[] = []> = T extends `${infer Head}${infer Rest}` ? LengthOfString<Rest, [Head, ...Length]> : Length['length']
提出日時 | 2023-05-08 01:44:09 |
---|---|
問題 | Length of String |
ユーザー | Dowanna |
ステータス | Accepted |
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<LengthOfString<''>, 0>>, Expect<Equal<LengthOfString<'kumiko'>, 6>>, Expect<Equal<LengthOfString<'reina'>, 5>>, Expect<Equal<LengthOfString<'Sound! Euphonium'>, 16>>, ]