Skip to content

Commit

Permalink
feat: solved day 7 & 8 type challenges
Browse files Browse the repository at this point in the history
Signed-off-by: rajput-hemant <rajput.hemant2001@gmail.com>
  • Loading branch information
rajput-hemant committed Dec 18, 2023
1 parent c3ac00e commit 3b964a9
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
43 changes: 43 additions & 0 deletions advent-of-typescript/2023/day_7.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Equal, Expect } from "type-testing";

type AppendGood<T> = { [K in keyof T as `good_${string & K}`]: T[K] };

/* -----------------------------------------------------------------------------------------------
* Code Here
* -----------------------------------------------------------------------------------------------*/

/* -----------------------------------------------------------------------------------------------
* Do not edit below this line
* -----------------------------------------------------------------------------------------------*/

type WellBehavedList = {
tom: { address: "1 candy cane lane" };
timmy: { address: "43 chocolate dr" };
trash: { address: "637 starlight way" };
candace: { address: "12 aurora" };
};
type test_wellBehaved_actual = AppendGood<WellBehavedList>;
// ^?
type test_wellBehaved_expected = {
good_tom: { address: "1 candy cane lane" };
good_timmy: { address: "43 chocolate dr" };
good_trash: { address: "637 starlight way" };
good_candace: { address: "12 aurora" };
};
type test_wellBehaved = Expect<
Equal<test_wellBehaved_expected, test_wellBehaved_actual>
>;

type Unrelated = {
dont: "cheat";
play: "fair";
};
type test_Unrelated_actual = AppendGood<Unrelated>;
// ^?
type test_Unrelated_expected = {
good_dont: "cheat";
good_play: "fair";
};
type test_Unrelated = Expect<
Equal<test_Unrelated_expected, test_Unrelated_actual>
>;
41 changes: 41 additions & 0 deletions advent-of-typescript/2023/day_8.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Equal, Expect } from "type-testing";

/* -----------------------------------------------------------------------------------------------
* Code here
* -----------------------------------------------------------------------------------------------*/

type RemoveNaughtyChildren<T> = {
[K in keyof T as K extends `naughty_${string}` ? never : K]: T[K];
};

/* -----------------------------------------------------------------------------------------------
* Do not edit below this line
* -----------------------------------------------------------------------------------------------*/

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>
>;

0 comments on commit 3b964a9

Please sign in to comment.