Skip to content

Commit aa5a54b

Browse files
committed
add lesson 10
1 parent a69d774 commit aa5a54b

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

src/sandbox.ts

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
// let greet: Function = () => {
2-
// console.log('hello, world');
3-
// }
4-
5-
// greet = 'hello';
6-
7-
// greet = () => {
8-
// console.log('hello, again');
9-
// }
1+
/// Lesson 9
102

113
type StringOrNum = string | number;
124
type objWithName = { name: string, uid: StringOrNum };
@@ -21,4 +13,31 @@ const greet = (user: objWithName) => {
2113

2214
const greetAgain = (user: objWithName) => {
2315
console.log(`${user.name} says hello again`);
16+
}
17+
18+
/// Lesson 10
19+
20+
// let greet: Function
21+
22+
// example 1
23+
let greetF: (a: string, b: string) => void;
24+
greetF = (name: string, greeting: string) => {
25+
console.log(`${name} says ${greeting}`);
26+
}
27+
28+
// example 2
29+
let calc: (a: number, b: number, c: string) => number;
30+
calc = (numOne: number, numTwo: number, action: string): number => {
31+
if (action === 'add') {
32+
return numOne + numTwo;
33+
} else {
34+
return numOne - numTwo;
35+
}
36+
}
37+
38+
// example 3
39+
type person = { name: string, age: number };
40+
let logDetailsO: (obj: { name: string, age: number }) => void;
41+
logDetailsO = (ninja: person) => {
42+
console.log(`${ninja.name} is ${ninja.age} years old`);
2443
}

0 commit comments

Comments
 (0)