Skip to content

Commit

Permalink
feat: solved day 5 & 6 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 16, 2023
1 parent dd0493d commit 5cebc83
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
48 changes: 48 additions & 0 deletions advent-of-typescript/2023/day_05.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Equal, Expect } from "type-testing";

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

type SantasList<T extends readonly Object[], U extends readonly Object[]> = [
...T,
...U,
];

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

const bads = ["tommy", "trash"] as const;
const goods = ["bash", "tru"] as const;

type test_0_actual = SantasList<typeof bads, typeof goods>;
// ^?
type test_0_expected = ["tommy", "trash", "bash", "tru"];
type test_0 = Expect<Equal<test_0_actual, test_0_expected>>;

type test_1_actual = SantasList<[], []>;
// ^?
type test_1_expected = [];
type test_1 = Expect<Equal<test_1_actual, test_1_expected>>;

type test_2_actual = SantasList<[], ["trash"]>;
// ^?
type test_2_expected = ["trash"];
type test_2 = Expect<Equal<test_2_actual, test_2_expected>>;

type test_3_actual = SantasList<["john"], ["ashley", "elliot", "ziltoid"]>;
// ^?
type test_3_expected = ["john", "ashley", "elliot", "ziltoid"];
type test_3 = Expect<Equal<test_3_actual, test_3_expected>>;

type test_4_actual = SantasList<
["1", 2, "3"],
[false, boolean, "4", ["nested"]]
>;
// ^?
type test_4_expected = ["1", 2, "3", false, boolean, "4", ["nested"]];
type test_4 = Expect<Equal<test_4_actual, test_4_expected>>;

// @ts-expect-error
type error_0 = SantasList<null, undefined>;
35 changes: 35 additions & 0 deletions advent-of-typescript/2023/day_06.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Equal, Expect } from "type-testing";

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

type FilterChildrenBy<T, U> = Exclude<T, U>;

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

type test_0_actual = FilterChildrenBy<
// ^?
"nice" | "nice" | "nice",
"naughty"
>;
type test_0_expected = "nice";
type test_0 = Expect<Equal<test_0_expected, test_0_actual>>;

type test_1_actual = FilterChildrenBy<
// ^?
"nice" | "naughty" | "naughty",
"naughty"
>;
type test_1_expected = "nice";
type test_1 = Expect<Equal<test_1_expected, test_1_actual>>;

type test_2_actual = FilterChildrenBy<
// ^?
string | number | (() => void),
Function
>;
type test_2_expected = string | number;
type test_2 = Expect<Equal<test_2_expected, test_2_actual>>;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"lint-staged": {
"*.ts": [
"oxlint --fix .",
"prettier . --cache"
"prettier ."
]
},
"commitlint": {
Expand Down

0 comments on commit 5cebc83

Please sign in to comment.