Skip to content

Commit 4d04c43

Browse files
committed
Added more exercises
1 parent d5d208e commit 4d04c43

14 files changed

+78
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const productPrices = {
2+
Apple: 1.2,
3+
Banana: 0.5,
4+
Orange: 0.8,
5+
};
6+
7+
const getPrice = (productName: string) => {
8+
return productPrices[productName];
9+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const productPrices = {
2+
Apple: 1.2,
3+
Banana: 0.5,
4+
Orange: 0.8,
5+
};
6+
7+
const getPrice = (productName: keyof typeof productPrices) => {
8+
return productPrices[productName];
9+
};
10+
11+
getPrice("Apple");
12+
13+
// @ts-expect-error
14+
getPrice("Pear");
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const productPrices: Record<string, number> = {
2+
Apple: 1.2,
3+
Banana: 0.5,
4+
Orange: 0.8,
5+
};
6+
7+
const getPrice = (productName: string) => {
8+
return productPrices[productName];
9+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const productPrices = {
2+
Apple: 1.2,
3+
Banana: 0.5,
4+
Orange: 0.8,
5+
};
6+
7+
const getPrice = (productName: string) => {
8+
return productPrices[productName as keyof typeof productPrices];
9+
};

src/006-expression-of-type-x-cant-be-used-to-index-type-y.solution.ts

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class User {
2+
private username: string;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class User {
2+
private username: string = "";
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class User {
2+
private username: string;
3+
4+
constructor() {
5+
this.username = "";
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class User {
2+
private username?: string;
3+
}

src/007-property-x-has-no-initializer-and-is-not-definitely-assigned-in-the-constructor.solution.ts

Whitespace-only changes.

0 commit comments

Comments
 (0)