Skip to content

Commit a22f9c5

Browse files
committed
completed solutions to 9
1 parent f9fd9ac commit a22f9c5

6 files changed

+19
-7
lines changed

src/04-optional-params.problem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect, it } from "vitest";
22

3-
export const getName = (first: string, last: string) => {
3+
export const getName = (first: string, last?: string) => {
44
if (last) {
55
return `${first} ${last}`;
66
}

src/05-assigning-types-to-variables.problem.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ interface User {
1111
* How do we ensure that defaultUser is of type User
1212
* at THIS LINE - not further down in the code?
1313
*/
14-
const defaultUser = {};
14+
const defaultUser: User = {
15+
id: 1,
16+
firstName: "Kyle",
17+
lastName: "Noad",
18+
isAdmin: true
19+
20+
};
1521

1622
const getUserId = (user: User) => {
1723
return user.id;

src/06-unions.problem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ interface User {
88
* - 'user'
99
* - 'super-admin'
1010
*/
11-
role: string;
11+
role: 'admin' | 'user' | 'super-admin';
1212
}
1313

1414
export const defaultUser: User = {

src/07-arrays.problem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ interface User {
33
firstName: string;
44
lastName: string;
55
role: "admin" | "user" | "super-admin";
6-
posts: Post;
6+
posts: Post[];
77
}
88

99
interface Post {

src/08-function-return-type-annotations.problem.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@ interface Post {
1717
* How do we ensure that makeUser ALWAYS
1818
* returns a user?
1919
*/
20-
const makeUser = () => {
21-
return {};
20+
const makeUser = (): User => {
21+
return {
22+
id: 1,
23+
firstName: "Kyle",
24+
lastName: "Noad",
25+
role: "super-admin",
26+
posts: [{id: 1, title: "hello"}]
27+
};
2228
};
2329

2430
it("Should return a valid user", () => {

src/09-promises.problem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ interface LukeSkywalker {
99
gender: string;
1010
}
1111

12-
export const fetchLukeSkywalker = async (): LukeSkywalker => {
12+
export const fetchLukeSkywalker = async (): Promise<LukeSkywalker> => {
1313
const data = await fetch("https://swapi.py4e.com/api/people/1").then(
1414
(res) => {
1515
return res.json();

0 commit comments

Comments
 (0)