-
Notifications
You must be signed in to change notification settings - Fork 0
/
14.ts
25 lines (21 loc) · 804 Bytes
/
14.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 DecipherNaughtyList<
List,
Acc extends Array<string> = [],
> = List extends `${infer Tizio}/${infer Rest}`
? DecipherNaughtyList<Rest, [...Acc, Tizio]>
: Acc["length"] extends 0
? List
: [...Acc, List][number];
type test_0_actual = DecipherNaughtyList<"timmy/jimmy">;
// ^?
type test_0_expected = "jimmy" | "timmy";
type test_0 = Expect<Equal<test_0_expected, test_0_actual>>;
type test_1_actual = DecipherNaughtyList<"elliot">;
// ^?
type test_1_expected = "elliot";
type test_1 = Expect<Equal<test_1_expected, test_1_actual>>;
type test_2_actual = DecipherNaughtyList<"melkey/prime/theo/trash">;
// ^?
type test_2_expected = "melkey" | "prime" | "theo" | "trash";
type test_2 = Expect<Equal<test_2_expected, test_2_actual>>;