Skip to content

Commit 093f76a

Browse files
committed
Add tests
1 parent 1610e19 commit 093f76a

File tree

4 files changed

+250
-0
lines changed

4 files changed

+250
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//// [tailRecursiveConditionalTypes.ts]
2+
type Trim<S extends string> =
3+
S extends ` ${infer T}` ? Trim<T> :
4+
S extends `${infer T} ` ? Trim<T> :
5+
S;
6+
7+
type T10 = Trim<' hello '>;
8+
type T11 = Trim<' hello '>;
9+
10+
type GetChars<S> = GetCharsRec<S, never>;
11+
type GetCharsRec<S, Acc> =
12+
S extends `${infer Char}${infer Rest}` ? GetCharsRec<Rest, Char | Acc> : Acc;
13+
14+
type T20 = GetChars<'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'>;
15+
16+
type Reverse<T> = any[] extends T ? T : ReverseRec<T, []>;
17+
type ReverseRec<T, Acc extends unknown[]> =
18+
T extends [infer Head, ...infer Tail] ? ReverseRec<Tail, [Head, ...Acc]> : Acc;
19+
20+
type T30 = Reverse<[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]>;
21+
type T31 = Reverse<string[]>;
22+
23+
type TupleOf<T, N extends number> = number extends N ? T[] : TupleOfRec<T, N, []>;
24+
type TupleOfRec<T, N extends number, Acc extends unknown[]> =
25+
Acc["length"] extends N ? Acc : TupleOfRec<T, N, [T, ...Acc]>;
26+
27+
type T40 = TupleOf<any, 200>;
28+
type T41 = TupleOf<any, number>;
29+
30+
31+
//// [tailRecursiveConditionalTypes.js]
32+
"use strict";
33+
34+
35+
//// [tailRecursiveConditionalTypes.d.ts]
36+
declare type Trim<S extends string> = S extends ` ${infer T}` ? Trim<T> : S extends `${infer T} ` ? Trim<T> : S;
37+
declare type T10 = Trim<' hello '>;
38+
declare type T11 = Trim<' hello '>;
39+
declare type GetChars<S> = GetCharsRec<S, never>;
40+
declare type GetCharsRec<S, Acc> = S extends `${infer Char}${infer Rest}` ? GetCharsRec<Rest, Char | Acc> : Acc;
41+
declare type T20 = GetChars<'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'>;
42+
declare type Reverse<T> = any[] extends T ? T : ReverseRec<T, []>;
43+
declare type ReverseRec<T, Acc extends unknown[]> = T extends [infer Head, ...infer Tail] ? ReverseRec<Tail, [Head, ...Acc]> : Acc;
44+
declare type T30 = Reverse<[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]>;
45+
declare type T31 = Reverse<string[]>;
46+
declare type TupleOf<T, N extends number> = number extends N ? T[] : TupleOfRec<T, N, []>;
47+
declare type TupleOfRec<T, N extends number, Acc extends unknown[]> = Acc["length"] extends N ? Acc : TupleOfRec<T, N, [T, ...Acc]>;
48+
declare type T40 = TupleOf<any, 200>;
49+
declare type T41 = TupleOf<any, number>;
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
=== tests/cases/compiler/tailRecursiveConditionalTypes.ts ===
2+
type Trim<S extends string> =
3+
>Trim : Symbol(Trim, Decl(tailRecursiveConditionalTypes.ts, 0, 0))
4+
>S : Symbol(S, Decl(tailRecursiveConditionalTypes.ts, 0, 10))
5+
6+
S extends ` ${infer T}` ? Trim<T> :
7+
>S : Symbol(S, Decl(tailRecursiveConditionalTypes.ts, 0, 10))
8+
>T : Symbol(T, Decl(tailRecursiveConditionalTypes.ts, 1, 23))
9+
>Trim : Symbol(Trim, Decl(tailRecursiveConditionalTypes.ts, 0, 0))
10+
>T : Symbol(T, Decl(tailRecursiveConditionalTypes.ts, 1, 23))
11+
12+
S extends `${infer T} ` ? Trim<T> :
13+
>S : Symbol(S, Decl(tailRecursiveConditionalTypes.ts, 0, 10))
14+
>T : Symbol(T, Decl(tailRecursiveConditionalTypes.ts, 2, 22))
15+
>Trim : Symbol(Trim, Decl(tailRecursiveConditionalTypes.ts, 0, 0))
16+
>T : Symbol(T, Decl(tailRecursiveConditionalTypes.ts, 2, 22))
17+
18+
S;
19+
>S : Symbol(S, Decl(tailRecursiveConditionalTypes.ts, 0, 10))
20+
21+
type T10 = Trim<' hello '>;
22+
>T10 : Symbol(T10, Decl(tailRecursiveConditionalTypes.ts, 3, 6))
23+
>Trim : Symbol(Trim, Decl(tailRecursiveConditionalTypes.ts, 0, 0))
24+
25+
type T11 = Trim<' hello '>;
26+
>T11 : Symbol(T11, Decl(tailRecursiveConditionalTypes.ts, 5, 170))
27+
>Trim : Symbol(Trim, Decl(tailRecursiveConditionalTypes.ts, 0, 0))
28+
29+
type GetChars<S> = GetCharsRec<S, never>;
30+
>GetChars : Symbol(GetChars, Decl(tailRecursiveConditionalTypes.ts, 6, 170))
31+
>S : Symbol(S, Decl(tailRecursiveConditionalTypes.ts, 8, 14))
32+
>GetCharsRec : Symbol(GetCharsRec, Decl(tailRecursiveConditionalTypes.ts, 8, 41))
33+
>S : Symbol(S, Decl(tailRecursiveConditionalTypes.ts, 8, 14))
34+
35+
type GetCharsRec<S, Acc> =
36+
>GetCharsRec : Symbol(GetCharsRec, Decl(tailRecursiveConditionalTypes.ts, 8, 41))
37+
>S : Symbol(S, Decl(tailRecursiveConditionalTypes.ts, 9, 17))
38+
>Acc : Symbol(Acc, Decl(tailRecursiveConditionalTypes.ts, 9, 19))
39+
40+
S extends `${infer Char}${infer Rest}` ? GetCharsRec<Rest, Char | Acc> : Acc;
41+
>S : Symbol(S, Decl(tailRecursiveConditionalTypes.ts, 9, 17))
42+
>Char : Symbol(Char, Decl(tailRecursiveConditionalTypes.ts, 10, 22))
43+
>Rest : Symbol(Rest, Decl(tailRecursiveConditionalTypes.ts, 10, 35))
44+
>GetCharsRec : Symbol(GetCharsRec, Decl(tailRecursiveConditionalTypes.ts, 8, 41))
45+
>Rest : Symbol(Rest, Decl(tailRecursiveConditionalTypes.ts, 10, 35))
46+
>Char : Symbol(Char, Decl(tailRecursiveConditionalTypes.ts, 10, 22))
47+
>Acc : Symbol(Acc, Decl(tailRecursiveConditionalTypes.ts, 9, 19))
48+
>Acc : Symbol(Acc, Decl(tailRecursiveConditionalTypes.ts, 9, 19))
49+
50+
type T20 = GetChars<'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'>;
51+
>T20 : Symbol(T20, Decl(tailRecursiveConditionalTypes.ts, 10, 81))
52+
>GetChars : Symbol(GetChars, Decl(tailRecursiveConditionalTypes.ts, 6, 170))
53+
54+
type Reverse<T> = any[] extends T ? T : ReverseRec<T, []>;
55+
>Reverse : Symbol(Reverse, Decl(tailRecursiveConditionalTypes.ts, 12, 86))
56+
>T : Symbol(T, Decl(tailRecursiveConditionalTypes.ts, 14, 13))
57+
>T : Symbol(T, Decl(tailRecursiveConditionalTypes.ts, 14, 13))
58+
>T : Symbol(T, Decl(tailRecursiveConditionalTypes.ts, 14, 13))
59+
>ReverseRec : Symbol(ReverseRec, Decl(tailRecursiveConditionalTypes.ts, 14, 58))
60+
>T : Symbol(T, Decl(tailRecursiveConditionalTypes.ts, 14, 13))
61+
62+
type ReverseRec<T, Acc extends unknown[]> =
63+
>ReverseRec : Symbol(ReverseRec, Decl(tailRecursiveConditionalTypes.ts, 14, 58))
64+
>T : Symbol(T, Decl(tailRecursiveConditionalTypes.ts, 15, 16))
65+
>Acc : Symbol(Acc, Decl(tailRecursiveConditionalTypes.ts, 15, 18))
66+
67+
T extends [infer Head, ...infer Tail] ? ReverseRec<Tail, [Head, ...Acc]> : Acc;
68+
>T : Symbol(T, Decl(tailRecursiveConditionalTypes.ts, 15, 16))
69+
>Head : Symbol(Head, Decl(tailRecursiveConditionalTypes.ts, 16, 20))
70+
>Tail : Symbol(Tail, Decl(tailRecursiveConditionalTypes.ts, 16, 35))
71+
>ReverseRec : Symbol(ReverseRec, Decl(tailRecursiveConditionalTypes.ts, 14, 58))
72+
>Tail : Symbol(Tail, Decl(tailRecursiveConditionalTypes.ts, 16, 35))
73+
>Head : Symbol(Head, Decl(tailRecursiveConditionalTypes.ts, 16, 20))
74+
>Acc : Symbol(Acc, Decl(tailRecursiveConditionalTypes.ts, 15, 18))
75+
>Acc : Symbol(Acc, Decl(tailRecursiveConditionalTypes.ts, 15, 18))
76+
77+
type T30 = Reverse<[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]>;
78+
>T30 : Symbol(T30, Decl(tailRecursiveConditionalTypes.ts, 16, 83))
79+
>Reverse : Symbol(Reverse, Decl(tailRecursiveConditionalTypes.ts, 12, 86))
80+
81+
type T31 = Reverse<string[]>;
82+
>T31 : Symbol(T31, Decl(tailRecursiveConditionalTypes.ts, 18, 171))
83+
>Reverse : Symbol(Reverse, Decl(tailRecursiveConditionalTypes.ts, 12, 86))
84+
85+
type TupleOf<T, N extends number> = number extends N ? T[] : TupleOfRec<T, N, []>;
86+
>TupleOf : Symbol(TupleOf, Decl(tailRecursiveConditionalTypes.ts, 19, 29))
87+
>T : Symbol(T, Decl(tailRecursiveConditionalTypes.ts, 21, 13))
88+
>N : Symbol(N, Decl(tailRecursiveConditionalTypes.ts, 21, 15))
89+
>N : Symbol(N, Decl(tailRecursiveConditionalTypes.ts, 21, 15))
90+
>T : Symbol(T, Decl(tailRecursiveConditionalTypes.ts, 21, 13))
91+
>TupleOfRec : Symbol(TupleOfRec, Decl(tailRecursiveConditionalTypes.ts, 21, 82))
92+
>T : Symbol(T, Decl(tailRecursiveConditionalTypes.ts, 21, 13))
93+
>N : Symbol(N, Decl(tailRecursiveConditionalTypes.ts, 21, 15))
94+
95+
type TupleOfRec<T, N extends number, Acc extends unknown[]> =
96+
>TupleOfRec : Symbol(TupleOfRec, Decl(tailRecursiveConditionalTypes.ts, 21, 82))
97+
>T : Symbol(T, Decl(tailRecursiveConditionalTypes.ts, 22, 16))
98+
>N : Symbol(N, Decl(tailRecursiveConditionalTypes.ts, 22, 18))
99+
>Acc : Symbol(Acc, Decl(tailRecursiveConditionalTypes.ts, 22, 36))
100+
101+
Acc["length"] extends N ? Acc : TupleOfRec<T, N, [T, ...Acc]>;
102+
>Acc : Symbol(Acc, Decl(tailRecursiveConditionalTypes.ts, 22, 36))
103+
>N : Symbol(N, Decl(tailRecursiveConditionalTypes.ts, 22, 18))
104+
>Acc : Symbol(Acc, Decl(tailRecursiveConditionalTypes.ts, 22, 36))
105+
>TupleOfRec : Symbol(TupleOfRec, Decl(tailRecursiveConditionalTypes.ts, 21, 82))
106+
>T : Symbol(T, Decl(tailRecursiveConditionalTypes.ts, 22, 16))
107+
>N : Symbol(N, Decl(tailRecursiveConditionalTypes.ts, 22, 18))
108+
>T : Symbol(T, Decl(tailRecursiveConditionalTypes.ts, 22, 16))
109+
>Acc : Symbol(Acc, Decl(tailRecursiveConditionalTypes.ts, 22, 36))
110+
111+
type T40 = TupleOf<any, 200>;
112+
>T40 : Symbol(T40, Decl(tailRecursiveConditionalTypes.ts, 23, 66))
113+
>TupleOf : Symbol(TupleOf, Decl(tailRecursiveConditionalTypes.ts, 19, 29))
114+
115+
type T41 = TupleOf<any, number>;
116+
>T41 : Symbol(T41, Decl(tailRecursiveConditionalTypes.ts, 25, 29))
117+
>TupleOf : Symbol(TupleOf, Decl(tailRecursiveConditionalTypes.ts, 19, 29))
118+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
=== tests/cases/compiler/tailRecursiveConditionalTypes.ts ===
2+
type Trim<S extends string> =
3+
>Trim : Trim<S>
4+
5+
S extends ` ${infer T}` ? Trim<T> :
6+
S extends `${infer T} ` ? Trim<T> :
7+
S;
8+
9+
type T10 = Trim<' hello '>;
10+
>T10 : "hello"
11+
12+
type T11 = Trim<' hello '>;
13+
>T11 : "hello"
14+
15+
type GetChars<S> = GetCharsRec<S, never>;
16+
>GetChars : GetChars<S>
17+
18+
type GetCharsRec<S, Acc> =
19+
>GetCharsRec : GetCharsRec<S, Acc>
20+
21+
S extends `${infer Char}${infer Rest}` ? GetCharsRec<Rest, Char | Acc> : Acc;
22+
23+
type T20 = GetChars<'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'>;
24+
>T20 : "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z" | "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" | "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
25+
26+
type Reverse<T> = any[] extends T ? T : ReverseRec<T, []>;
27+
>Reverse : Reverse<T>
28+
29+
type ReverseRec<T, Acc extends unknown[]> =
30+
>ReverseRec : ReverseRec<T, Acc>
31+
32+
T extends [infer Head, ...infer Tail] ? ReverseRec<Tail, [Head, ...Acc]> : Acc;
33+
34+
type T30 = Reverse<[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]>;
35+
>T30 : [9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
36+
37+
type T31 = Reverse<string[]>;
38+
>T31 : string[]
39+
40+
type TupleOf<T, N extends number> = number extends N ? T[] : TupleOfRec<T, N, []>;
41+
>TupleOf : TupleOf<T, N>
42+
43+
type TupleOfRec<T, N extends number, Acc extends unknown[]> =
44+
>TupleOfRec : TupleOfRec<T, N, Acc>
45+
46+
Acc["length"] extends N ? Acc : TupleOfRec<T, N, [T, ...Acc]>;
47+
48+
type T40 = TupleOf<any, 200>;
49+
>T40 : [any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any, any]
50+
51+
type T41 = TupleOf<any, number>;
52+
>T41 : any[]
53+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// @strict: true
2+
// @declaration: true
3+
4+
type Trim<S extends string> =
5+
S extends ` ${infer T}` ? Trim<T> :
6+
S extends `${infer T} ` ? Trim<T> :
7+
S;
8+
9+
type T10 = Trim<' hello '>;
10+
type T11 = Trim<' hello '>;
11+
12+
type GetChars<S> = GetCharsRec<S, never>;
13+
type GetCharsRec<S, Acc> =
14+
S extends `${infer Char}${infer Rest}` ? GetCharsRec<Rest, Char | Acc> : Acc;
15+
16+
type T20 = GetChars<'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'>;
17+
18+
type Reverse<T> = any[] extends T ? T : ReverseRec<T, []>;
19+
type ReverseRec<T, Acc extends unknown[]> =
20+
T extends [infer Head, ...infer Tail] ? ReverseRec<Tail, [Head, ...Acc]> : Acc;
21+
22+
type T30 = Reverse<[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9]>;
23+
type T31 = Reverse<string[]>;
24+
25+
type TupleOf<T, N extends number> = number extends N ? T[] : TupleOfRec<T, N, []>;
26+
type TupleOfRec<T, N extends number, Acc extends unknown[]> =
27+
Acc["length"] extends N ? Acc : TupleOfRec<T, N, [T, ...Acc]>;
28+
29+
type T40 = TupleOf<any, 200>;
30+
type T41 = TupleOf<any, number>;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy