Skip to content

Commit c34d616

Browse files
committed
2 parents cfc3722 + 023cbbf commit c34d616

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Quickstart
44

5+
Clone this repo or [open in Gitpod](https://gitpod.io/#https://github.com/total-typescript/beginners-typescript).
6+
57
```sh
68
# Installs all dependenciesG
79
npm install

scripts/exercise.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ chokidar.watch(exerciseFile).on("all", (event, path) => {
4242
console.clear();
4343
if (containsVitest) {
4444
console.log("Running tests...");
45-
execSync(`vitest run ${exerciseFile} --passWithNoTests`, {
45+
execSync(`vitest run "${exerciseFile}" --passWithNoTests`, {
4646
stdio: "inherit",
4747
});
4848
}
4949
console.log("Checking types...");
50-
execSync(`tsc ${exerciseFile} --noEmit --strict`, {
50+
execSync(`tsc "${exerciseFile}" --noEmit --strict`, {
5151
stdio: "inherit",
5252
});
5353
console.log("Typecheck complete. You finished the exercise!");

src/13-catch-blocks.solution.2.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ const tryCatchDemo = (state: "fail" | "succeed") => {
66
throw new Error("Failure!");
77
}
88
} catch (e) {
9-
if (e instanceof Error) {
10-
return e.message;
11-
}
9+
return (e as Error).message;
1210
}
1311
};
1412

src/13-catch-blocks.solution.3.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { expect, it } from "vitest";
2+
3+
const tryCatchDemo = (state: "fail" | "succeed") => {
4+
try {
5+
if (state === "fail") {
6+
throw new Error("Failure!");
7+
}
8+
} catch (e) {
9+
if (e instanceof Error) {
10+
return e.message;
11+
}
12+
}
13+
};
14+
15+
it("Should return the message when it fails", () => {
16+
expect(tryCatchDemo("fail")).toEqual("Failure!");
17+
});

0 commit comments

Comments
 (0)