-
Notifications
You must be signed in to change notification settings - Fork 0
/
00651-hard-length-of-string-2.ts
42 lines (36 loc) · 2.97 KB
/
00651-hard-length-of-string-2.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// ============= Test Cases =============
import type { Equal, IsTrue } from './test-utils'
type cases = [
IsTrue<Equal<LengthOfString<''>, 0>>,
IsTrue<Equal<LengthOfString<'1'>, 1>>,
IsTrue<Equal<LengthOfString<'12'>, 2>>,
IsTrue<Equal<LengthOfString<'123'>, 3>>,
IsTrue<Equal<LengthOfString<'1234'>, 4>>,
IsTrue<Equal<LengthOfString<'12345'>, 5>>,
IsTrue<Equal<LengthOfString<'123456'>, 6>>,
IsTrue<Equal<LengthOfString<'1234567'>, 7>>,
IsTrue<Equal<LengthOfString<'12345678'>, 8>>,
IsTrue<Equal<LengthOfString<'123456789'>, 9>>,
IsTrue<Equal<LengthOfString<'1234567890'>, 10>>,
IsTrue<Equal<LengthOfString<'12345678901'>, 11>>,
IsTrue<Equal<LengthOfString<'123456789012'>, 12>>,
IsTrue<Equal<LengthOfString<'1234567890123'>, 13>>,
IsTrue<Equal<LengthOfString<'12345678901234'>, 14>>,
IsTrue<Equal<LengthOfString<'123456789012345'>, 15>>,
IsTrue<Equal<LengthOfString<'1234567890123456'>, 16>>,
IsTrue<Equal<LengthOfString<'12345678901234567'>, 17>>,
IsTrue<Equal<LengthOfString<'123456789012345678'>, 18>>,
IsTrue<Equal<LengthOfString<'1234567890123456789'>, 19>>,
IsTrue<Equal<LengthOfString<'12345678901234567890'>, 20>>,
IsTrue<Equal<LengthOfString<'123456789012345678901'>, 21>>,
IsTrue<Equal<LengthOfString<'1234567890123456789012'>, 22>>,
IsTrue<Equal<LengthOfString<'12345678901234567890123'>, 23>>,
IsTrue<Equal<LengthOfString<'aaaaaaaaaaaaggggggggggggggggggggkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'>, 272>>,
IsTrue<Equal<LengthOfString<'000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'>, 999>>,
]
// ============= Your Code Here =============
type LengthOfString<S extends string, Counter extends unknown[] = []> =
S extends `${infer _}${infer Rest}` ? LengthOfString<Rest, [...Counter, 1]> : Counter['length']
type Test1 = LengthOfString<'123'>
const array = [1, 2, 3] as const
type Test2 = (typeof array)[number]