Type Challenges Judge

Length of String

提出詳細

type CreateArray<N, D extends readonly 0[] = []> = D["length"] extends N ? D: CreateArray<N, [...D, 0]>; type Sum<X, Y> = [...CreateArray<X>, ...CreateArray<Y>]["length"]; type LengthOfString<S extends string, N = 0> = S extends `${infer F}${infer Tail}` ? LengthOfString<Tail, Sum<N, 1>> :N
提出日時2023-12-11 23:52:59
問題Length of String
ユーザーwaki285
ステータス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>>, ]