-
Notifications
You must be signed in to change notification settings - Fork 0
/
8.ts
35 lines (31 loc) · 958 Bytes
/
8.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
import { Expect, Equal } from "type-testing";
type NoNaughthyAllowed<P> = P extends `naughty_${string}` ? never : P;
type RemoveNaughtyChildren<L> = {
[Prop in keyof L as NoNaughthyAllowed<Prop>]: L[Prop];
};
type SantasList = {
naughty_tom: { address: "1 candy cane lane" };
good_timmy: { address: "43 chocolate dr" };
naughty_trash: { address: "637 starlight way" };
naughty_candace: { address: "12 aurora" };
};
type test_wellBehaved_actual = RemoveNaughtyChildren<SantasList>;
// ^?
type test_wellBehaved_expected = {
good_timmy: { address: "43 chocolate dr" };
};
type test_wellBehaved = Expect<
Equal<test_wellBehaved_expected, test_wellBehaved_actual>
>;
type Unrelated = {
dont: "cheat";
naughty_play: "fair";
};
type test_Unrelated_actual = RemoveNaughtyChildren<Unrelated>;
// ^?
type test_Unrelated_expected = {
dont: "cheat";
};
type test_Unrelated = Expect<
Equal<test_Unrelated_expected, test_Unrelated_actual>
>;