diff --git a/.vscode/ext.config.json b/.vscode/ext.config.json
new file mode 100644
index 00000000..e1c35747
--- /dev/null
+++ b/.vscode/ext.config.json
@@ -0,0 +1,5 @@
+{
+ "disabled": [
+ "Codeium.codeium"
+ ]
+}
\ No newline at end of file
diff --git a/README.md b/README.md
index 17d76d19..45c333c3 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,5 @@
+# This is my personal fork for learning proposes.
+
## Quickstart
diff --git a/package.json b/package.json
index 1263eee7..af251048 100644
--- a/package.json
+++ b/package.json
@@ -63,4 +63,4 @@
"express": "^4.18.1",
"zod": "^3.17.10"
}
-}
+}
\ No newline at end of file
diff --git a/src/02-object-param.problem.ts b/src/02-object-param.problem.ts
deleted file mode 100644
index 8c331765..00000000
--- a/src/02-object-param.problem.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import { expect, it } from "vitest";
-
-export const addTwoNumbers = (params) => {
- return params.first + params.second;
-};
-
-it("Should add the two numbers together", () => {
- expect(
- addTwoNumbers({
- first: 2,
- second: 4,
- }),
- ).toEqual(6);
-
- expect(
- addTwoNumbers({
- first: 10,
- second: 20,
- }),
- ).toEqual(30);
-});
diff --git a/src/01-number.solution.ts b/src/done/01-number.problem.ts
similarity index 100%
rename from src/01-number.solution.ts
rename to src/done/01-number.problem.ts
diff --git a/src/01-number.problem.ts b/src/done/01-number.solution.ts
similarity index 77%
rename from src/01-number.problem.ts
rename to src/done/01-number.solution.ts
index 0f6286e0..5f21a88e 100644
--- a/src/01-number.problem.ts
+++ b/src/done/01-number.solution.ts
@@ -1,6 +1,6 @@
import { expect, it } from "vitest";
-export const addTwoNumbers = (a, b) => {
+export const addTwoNumbers = (a: number, b: number) => {
return a + b;
};
diff --git a/src/done/02-object-param.problem.ts b/src/done/02-object-param.problem.ts
new file mode 100644
index 00000000..9a11faf7
--- /dev/null
+++ b/src/done/02-object-param.problem.ts
@@ -0,0 +1,32 @@
+import { expect, it } from "vitest";
+
+interface AddTwoNumbersArgs {
+ first: number;
+ second: number;
+}
+
+// type AddTwoNumbersArgs = {
+// first: number;
+// second: number;
+// };
+
+export const addTwoNumbers = (params: AddTwoNumbersArgs) => {
+ // export const addTwoNumbers = (params: { first: number; second: number }) => {
+ return params.first + params.second;
+};
+
+it("Should add the two numbers together", () => {
+ expect(
+ addTwoNumbers({
+ first: 2,
+ second: 4,
+ })
+ ).toEqual(6);
+
+ expect(
+ addTwoNumbers({
+ first: 10,
+ second: 20,
+ })
+ ).toEqual(30);
+});
diff --git a/src/02-object-param.solution.1.ts b/src/done/02-object-param.solution.1.ts
similarity index 100%
rename from src/02-object-param.solution.1.ts
rename to src/done/02-object-param.solution.1.ts
diff --git a/src/02-object-param.solution.2.ts b/src/done/02-object-param.solution.2.ts
similarity index 100%
rename from src/02-object-param.solution.2.ts
rename to src/done/02-object-param.solution.2.ts
diff --git a/src/02-object-param.solution.3.ts b/src/done/02-object-param.solution.3.ts
similarity index 100%
rename from src/02-object-param.solution.3.ts
rename to src/done/02-object-param.solution.3.ts
diff --git a/src/03-optional-properties.problem.ts b/src/done/03-optional-properties.problem.ts
similarity index 71%
rename from src/03-optional-properties.problem.ts
rename to src/done/03-optional-properties.problem.ts
index 9ee58fcb..83fc3653 100644
--- a/src/03-optional-properties.problem.ts
+++ b/src/done/03-optional-properties.problem.ts
@@ -1,6 +1,7 @@
import { expect, it } from "vitest";
-export const getName = (params: { first: string; last: string }) => {
+// export const getName = (params: { first: string; last: string | undefined }) => {
+export const getName = (params: { first: string; last?: string }) => {
if (params.last) {
return `${params.first} ${params.last}`;
}
@@ -10,6 +11,7 @@ export const getName = (params: { first: string; last: string }) => {
it("Should work with just the first name", () => {
const name = getName({
first: "Matt",
+ // last: undefined,
});
expect(name).toEqual("Matt");
diff --git a/src/03-optional-properties.solution.ts b/src/done/03-optional-properties.solution.ts
similarity index 100%
rename from src/03-optional-properties.solution.ts
rename to src/done/03-optional-properties.solution.ts
diff --git a/src/04-optional-params.solution.ts b/src/done/04-optional-params.problem.ts
similarity index 100%
rename from src/04-optional-params.solution.ts
rename to src/done/04-optional-params.problem.ts
diff --git a/src/04-optional-params.problem.ts b/src/done/04-optional-params.solution.ts
similarity index 86%
rename from src/04-optional-params.problem.ts
rename to src/done/04-optional-params.solution.ts
index 023bb997..3c12b9f8 100644
--- a/src/04-optional-params.problem.ts
+++ b/src/done/04-optional-params.solution.ts
@@ -1,6 +1,6 @@
import { expect, it } from "vitest";
-export const getName = (first: string, last: string) => {
+export const getName = (first: string, last?: string) => {
if (last) {
return `${first} ${last}`;
}
diff --git a/src/05-assigning-types-to-variables.solution.ts b/src/done/05-assigning-types-to-variables.problem.ts
similarity index 100%
rename from src/05-assigning-types-to-variables.solution.ts
rename to src/done/05-assigning-types-to-variables.problem.ts
diff --git a/src/05-assigning-types-to-variables.problem.ts b/src/done/05-assigning-types-to-variables.solution.ts
similarity index 79%
rename from src/05-assigning-types-to-variables.problem.ts
rename to src/done/05-assigning-types-to-variables.solution.ts
index 50de8989..174c0fc0 100644
--- a/src/05-assigning-types-to-variables.problem.ts
+++ b/src/done/05-assigning-types-to-variables.solution.ts
@@ -11,7 +11,12 @@ interface User {
* How do we ensure that defaultUser is of type User
* at THIS LINE - not further down in the code?
*/
-const defaultUser = {};
+const defaultUser: User = {
+ id: 1,
+ firstName: "Matt",
+ lastName: "Pocock",
+ isAdmin: true,
+};
const getUserId = (user: User) => {
return user.id;
diff --git a/src/06-unions.problem.ts b/src/done/06-unions.problem.ts
similarity index 52%
rename from src/06-unions.problem.ts
rename to src/done/06-unions.problem.ts
index 55420fd0..f11cbf25 100644
--- a/src/06-unions.problem.ts
+++ b/src/done/06-unions.problem.ts
@@ -8,13 +8,19 @@ interface User {
* - 'user'
* - 'super-admin'
*/
- role: string;
+ // this is a union type::
+ role: Role;
}
+type Role = "admin" | "user" | SuperAdmin | { wow: boolean };
+
+type SuperAdmin = "super-admin";
export const defaultUser: User = {
id: 1,
firstName: "Matt",
lastName: "Pocock",
- // @ts-expect-error
- role: "I_SHOULD_NOT_BE_ALLOWED",
+ // // @ts-expect-error
+ // role: "I_SHOULD_NOT_BE_ALLOWED",
+ role: "super-admin",
+ // role: { wow: true },
};
diff --git a/src/06-unions.solution.ts b/src/done/06-unions.solution.ts
similarity index 100%
rename from src/06-unions.solution.ts
rename to src/done/06-unions.solution.ts
diff --git a/src/07-arrays.problem.ts b/src/done/07-arrays.problem.ts
similarity index 60%
rename from src/07-arrays.problem.ts
rename to src/done/07-arrays.problem.ts
index c18909ce..d79b466b 100644
--- a/src/07-arrays.problem.ts
+++ b/src/done/07-arrays.problem.ts
@@ -3,9 +3,24 @@ interface User {
firstName: string;
lastName: string;
role: "admin" | "user" | "super-admin";
- posts: Post;
+ // posts: Post[]; // option 1
+ // posts: Posts; // option 2
+ posts: Array; // option 2
}
+const myPostOption1: Post[] = [
+ {
+ id: 1,
+ title: "How I eat so much cheese",
+ },
+ {
+ id: 2,
+ title: "Why I don't eat more vegetables",
+ },
+];
+
+// type Posts = Array;
+
interface Post {
id: number;
title: string;
diff --git a/src/07-arrays.solution.1.ts b/src/done/07-arrays.solution.1.ts
similarity index 100%
rename from src/07-arrays.solution.1.ts
rename to src/done/07-arrays.solution.1.ts
diff --git a/src/07-arrays.solution.2.ts b/src/done/07-arrays.solution.2.ts
similarity index 100%
rename from src/07-arrays.solution.2.ts
rename to src/done/07-arrays.solution.2.ts
diff --git a/src/08-function-return-type-annotations.problem.ts b/src/done/08-function-return-type-annotations.problem.ts
similarity index 53%
rename from src/08-function-return-type-annotations.problem.ts
rename to src/done/08-function-return-type-annotations.problem.ts
index af1e7217..a856f348 100644
--- a/src/08-function-return-type-annotations.problem.ts
+++ b/src/done/08-function-return-type-annotations.problem.ts
@@ -4,22 +4,49 @@ interface User {
id: number;
firstName: string;
lastName: string;
- role: "admin" | "user" | "super-admin";
+ role: Role;
posts: Array;
}
+type Role = "admin" | "user" | "super-admin";
+
interface Post {
id: number;
title: string;
}
+const userToReturn: User = {
+ id: 1,
+ firstName: "Matt",
+ lastName: "Pocock",
+ role: "user",
+ posts: [
+ {
+ id: 1,
+ title: "How I eat so much cheese",
+ },
+ ],
+};
+
/**
* How do we ensure that makeUser ALWAYS
* returns a user?
*/
-const makeUser = () => {
- return {};
-};
+const makeUser = (): User => userToReturn;
+// const makeUser = (): User => {
+// return {
+// id: 1,
+// firstName: "Matt",
+// lastName: "Pocock",
+// role: "super-admin",
+// posts: [
+// {
+// id: 1,
+// title: "How I eat so much cheese",
+// },
+// ],
+// };
+// };
it("Should return a valid user", () => {
const user = makeUser();
diff --git a/src/08-function-return-type-annotations.solution.ts b/src/done/08-function-return-type-annotations.solution.ts
similarity index 100%
rename from src/08-function-return-type-annotations.solution.ts
rename to src/done/08-function-return-type-annotations.solution.ts
diff --git a/tsconfig.json b/tsconfig.json
index 2ca5a708..f17af1f3 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -2,7 +2,8 @@
"extends": "@total-typescript/tsconfig/bundler",
"compilerOptions": {
"noUncheckedIndexedAccess": false,
- "verbatimModuleSyntax": false
+ "verbatimModuleSyntax": false,
+ "strict": true
},
"include": [
"src"