Skip to content

Commit 94875b9

Browse files
committed
solved up to q18
1 parent a22f9c5 commit 94875b9

8 files changed

+20
-13
lines changed

src/10-set.problem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect, it } from "vitest";
22
import { Equal, Expect } from "./helpers/type-utils";
33

4-
const guitarists = new Set();
4+
const guitarists = new Set<string>();
55

66
guitarists.add("Jimi Hendrix");
77
guitarists.add("Eric Clapton");

src/11-record.problem.ts

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

33
const createCache = () => {
4-
const cache = {};
4+
const cache: Record<string, string> = {};
55

66
const add = (id: string, value: string) => {
77
cache[id] = value;

src/12-typeof-narrowing.problem.ts

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

3-
const coerceAmount = (amount: number | { amount: number }) => {};
3+
const coerceAmount = (amount: number | { amount: number }) => {
4+
if(typeof amount === "number"){
5+
return amount
6+
}else{
7+
return amount.amount
8+
}
9+
};
410

511
it("Should return the amount when passed an object", () => {
612
expect(coerceAmount({ amount: 20 })).toEqual(20);

src/13-catch-blocks.problem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const tryCatchDemo = (state: "fail" | "succeed") => {
55
if (state === "fail") {
66
throw new Error("Failure!");
77
}
8-
} catch (e) {
8+
} catch (e: any) {
99
return e.message;
1010
}
1111
};

src/14-extends.problem.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@ import { Equal, Expect } from "./helpers/type-utils";
66
* make it more DRY?
77
*/
88

9-
interface User {
10-
id: string;
9+
interface Base {
10+
id: string
11+
}
12+
13+
interface User extends Base{
1114
firstName: string;
1215
lastName: string;
1316
}
1417

15-
interface Post {
16-
id: string;
18+
interface Post extends Base{
1719
title: string;
1820
body: string;
1921
}
2022

21-
interface Comment {
22-
id: string;
23+
interface Comment extends Base {
2324
comment: string;
2425
}
2526

src/15-intersection.problem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface Post {
1414
* How do we type this return statement so it's both
1515
* User AND { posts: Post[] }
1616
*/
17-
export const getDefaultUserAndPosts = (): unknown => {
17+
export const getDefaultUserAndPosts = (): User & { posts: Post[] } => {
1818
return {
1919
id: "1",
2020
firstName: "Matt",

src/16-omit-and-pick.problem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ interface User {
1111
* firstName and lastName properties of User?
1212
*/
1313

14-
type MyType = unknown;
14+
type MyType = Omit<User, "id">;
1515

1616
type tests = [Expect<Equal<MyType, { firstName: string; lastName: string }>>];

src/17-function-types.problem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Equal, Expect } from "./helpers/type-utils";
33
/**
44
* How do we type onFocusChange?
55
*/
6-
const addListener = (onFocusChange: unknown) => {
6+
const addListener = (onFocusChange: (isFocused: boolean) => void) => {
77
window.addEventListener("focus", () => {
88
onFocusChange(true);
99
});

0 commit comments

Comments
 (0)