-
Notifications
You must be signed in to change notification settings - Fork 0
/
15.ts
25 lines (22 loc) · 737 Bytes
/
15.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
import { Expect, Equal } from "type-testing";
type BoxToys<
Toy extends string,
Times,
Acc extends string[] = [],
> = Acc["length"] extends Times
? Times extends Acc["length"]
? Acc
: BoxToys<Toy, Times, [...Acc, Toy]>
: BoxToys<Toy, Times, [...Acc, Toy]>;
type test_doll_actual = BoxToys<"doll", 1>;
// ^?
type test_doll_expected = ["doll"];
type test_doll = Expect<Equal<test_doll_expected, test_doll_actual>>;
type test_nutcracker_actual = BoxToys<"nutcracker", 3 | 4>;
// ^?
type test_nutcracker_expected =
| ["nutcracker", "nutcracker", "nutcracker"]
| ["nutcracker", "nutcracker", "nutcracker", "nutcracker"];
type test_nutcracker = Expect<
Equal<test_nutcracker_expected, test_nutcracker_actual>
>;