Skip to content

Commit 3579dbf

Browse files
authored
๐Ÿ”€: Udemy/Ts/section2/22 (#27)
* ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: issue templates ์ƒ์„ฑ Github์—์„œ ์ž‘์„ฑํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: pr-template ์ƒ์„ฑ Github์—์„œ ์ž‘์„ฑํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: pr-template ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: pr-template ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐Ÿšฉ: udemy section2์˜ 14๋ฒˆ ๊ฐ•์˜๋ฅผ ๋“ฃ๊ณ  ์‹ค์Šต์„ ํ–ˆ๋‹ค. * ๐Ÿšฉ: ํƒ€์ž… ํ• ๋‹น์€ ์ง€๊ธˆ๊นŒ์ง€ ํ•˜๋‚˜๋งŒ ๊ฐ€๋Šฅํ–ˆ๋‹ค. ์—ฌ๋Ÿฌ ํƒ€์ž…์„ ๊ต์ฐจ๋กœ ์‚ฌ์šฉํ•˜๋ฉด ๋ฐœ์ƒํ•˜๋Š” error * ๐Ÿšฉ: error TS 2365 ๋งค๊ฐœ๋ณ€์ˆ˜์˜ ํƒ• * ๐Ÿšฉ: ์—ฐ์‚ฐ์ด ํ—ˆ์šฉ๋˜์ง€ ์•Š๋Š” ํƒ€์ž… ์˜ˆ์‹œ * ๐Ÿšฉ: Union Type์œผ๋กœ ๋ฐœ์ƒํ•œ TS 2365 ๋ฌธ์ œ๋ฅผ if๋ฌธ์œผ๋กœ ์ •ํ™•ํ•œ ํƒ€์ž…์„ ๋ช…์‹œ, ์ง€์ • ํ•ด์คŒ์œผ๋กœ์จ ํ•ด๊ฒฐ
1 parent 8ce9575 commit 3579dbf

File tree

2 files changed

+46
-25
lines changed

2 files changed

+46
-25
lines changed

โ€Žsrc/app.ts

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
1-
const person: {
2-
name: string,
3-
age: number,
4-
hobbies: string[];
5-
role: (number | string)[];
6-
} = {
7-
name: 'Maximilian',
8-
age: 30,
9-
hobbies: ['Sports', 'Cooking'],
10-
role: [2, 'author']
11-
};
1+
function combine(n1: number | string, n2: number | string) {
2+
let result;
3+
if (typeof n1 === 'number' && typeof n2 === 'number') {
4+
result = n1 + n2;
5+
} else if (typeof n1 === 'string' && typeof n2 === 'string') {
6+
result = n1 + n2;
7+
} else {
8+
result = n1.toString() + n2.toString();
9+
} // ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•: if๋ฌธ์œผ๋กœ typeof๋กœ ๊ฐ ํƒ€์ž…๋“ค์ด ๋ฌด์—‡์ธ์ง€ ์‹๋ณ„ํ•œ ํ›„ ์—ฐ์‚ฐ์„ ์ ์šฉํ•œ๋‹ค. ์—ฐ์‚ฐ์ด ์ ์šฉ๋˜์ง€ ์•Š๋Š” ํƒ€์ž…๋“ค์€ ๋ชจ๋‘ string์œผ๋กœ ํ˜•๋ณ€ํ™˜ ํ›„ ์—ฐ์‚ฐ์„ ์‹œ์ผœ์ฃผ๋ฉด ๋œ๋‹ค. ๋”ฐ๋ผ์„œ ์œ ๋‹ˆ์˜จ ํƒ€์ž…์œผ๋กœ ์—ฌ๋Ÿฌ ํƒ€์ž…์„ ์œ ์—ฐํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์ง€๋งŒ ์ด๊ฒƒ๋“ค์„ ํ™œ์šฉํ•  ๋•Œ๋Š” ์ •ํ™•ํžˆ ์–ด๋–ค ํƒ€์ž…์„ ๋ฐ›๋Š”์ง€์— ๊ด€ํ•œ ๋กœ์ง์ด ๋ณดํ†ต ํ•จ์ˆ˜๋‚˜ ํด๋ž˜์Šค ๊ตฌ์กฐ์— ๋งŽ์ด ํ•„์š”ํ•˜๋‹ค.
10+
return result;
11+
}
12+
// Ts๊ฐ€ ์—ผ๋ คํ•˜๋Š” error์˜ ๊ทผ์›์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.
13+
// const b1: boolean = true;
14+
// const b2: boolean = false;
15+
// console.log(b1 + b2);
1216

13-
person.role.push('admin');
14-
person.role[1] = 10;
15-
person.role = [0, 'admin', 'user'];
17+
const CombineAges = combine(20, 30);
18+
console.log(CombineAges);
1619

17-
//any๋Š” ์–ด๋–ค ํƒ€์ž…์ด๋“  ํ—ˆ์šฉํ•˜๋Š” ํƒ€์ž…์ด๋‹ค. ์–ด๋–ป๊ฒŒ ๋ณด๋ฉด ์œ ์—ฐํ•˜๋‹ค๊ณ  ๋А๊ปด์ง€์งˆ์ง€ ๋ชจ๋ฅด๊ฒ ์ง€๋งŒ ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ์˜ ์žฅ์ ์„ ์ „ํ˜€ ํ™œ์šฉํ•˜์ง€ ๋ชปํ•˜๊ธฐ์— ์ข‹์€ ๋ฐฉ๋ฒ•์€ ์•„๋‹ˆ๋‹ค.
18-
let favoriteActivities: any[];
19-
favoriteActivities = ['Sports', 1]; //์ด๋ ‡๊ฒŒ ๋ฐฐ์—ด์— ๋งˆ๊ตฌ์žก์ด๋กœ ์„œ๋กœ ๋‹ค๋ฅธ ํƒ€์ž…์„ ๋„ฃ์–ด๋„ ์•„๋ฌด๋Ÿฐ ์—๋Ÿฌ๊ฐ€ ์ผ์–ด๋‚˜์ง€ ์•Š๋Š”๋‹ค.
20-
21-
console.log(person.name);
22-
23-
for (const hobby of person.hobbies) {
24-
console.log(hobby);
25-
}
20+
const CombineNames = combine('Max', 'Anna');
21+
console.log(CombineNames);

โ€Žsrc/basics.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function add(n1: number, n2: number, showResult: boolean, phrase: string) {
1+
function addTemplate(n1: number, n2: number, showResult: boolean, phrase: string) {
22
const result = n1 + n2; //result๋Š” number๋ผ๊ณ  ์ถ”๋ก ์„ ํ•œ๋‹ค.
33
if (showResult) {
44
console.log(result + phrase);
@@ -13,4 +13,29 @@ const printResult = true;
1313
const resultPhrase = 'Result is: ';
1414
// resultPhrase = 0; //error -> ํƒ€์ž… ์ถ”๋ก ์œผ๋กœ resultPhrase๋Š” string์ด๋‹ค. ๋”ฐ๋ผ 0์ด๋ผ๋Š” numberํƒ€์ž…์„ ํ• ๋‹นํ•  ์ˆ˜ ์—†๋‹ค.
1515

16-
add(number1, number2, printResult, resultPhrase);
16+
addTemplate(number1, number2, printResult, resultPhrase);
17+
18+
const person: {
19+
name: string,
20+
age: number,
21+
hobbies: string[];
22+
role: (number | string)[];
23+
} = {
24+
name: 'Maximilian',
25+
age: 30,
26+
hobbies: ['Sports', 'Cooking'],
27+
role: [2, 'author']
28+
};
29+
30+
person.role.push('admin');
31+
person.role[1] = 10;
32+
person.role = [0, 'admin', 'user'];
33+
34+
let favoriteActivities: any[];
35+
favoriteActivities = ['Sports', 1];
36+
37+
console.log(person.name);
38+
39+
for (const hobby of person.hobbies) {
40+
console.log(hobby);
41+
}

0 commit comments

Comments
ย (0)