Skip to content

Commit 0ea6332

Browse files
authored
๐Ÿ”€: Udemy/Ts/section2/24 (#29)
* ๐ŸŒฑ: 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๋ฒˆ ๊ฐ•์˜๋ฅผ ๋“ฃ๊ณ  ์‹ค์Šต์„ ํ–ˆ๋‹ค. * ๐Ÿšฉ: Alias Type์œผ๋กœ ํƒ€์ž… ๋ณ„์นญ ์ƒ์„ฑ * ๐Ÿšฉ: Alias Type์„ ํ™œ์šฉํ•œ Union Type ์ง€์ • ๋ฐฉ์‹๊ณผ ํ™œ์šฉ ์˜ˆ์‹œ
1 parent f745d48 commit 0ea6332

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

โ€Žsrc/app.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
//ํ•ญ์ƒ ์œ ๋‹ˆ์˜จ ํƒ€์ž…์„ ์ง€์ •ํ•˜๋Š” ๊ฒƒ์€ ๋งŽ์ด ๋ฒˆ๊ฑฐ๋กญ๋‹ค. ์ด์— alias ํƒ€์ž…์œผ๋กœ ์‚ฌ์šฉ์ž ์ง€์ • ํƒ€์ž…์„ ์ •ํ•  ์ˆ˜ ์žˆ๋‹ค. ์ฆ‰, ํƒ€์ž…์„ ์šฐ๋ฆฌ๊ฐ€ ๋‹ค๋กœ ๋ณ„์นญ์œผ๋กœ ๋งŒ๋“ค์–ด ๋‚ผ ์ˆ˜ ์žˆ๋‹ค.
2+
3+
type Combinable = number | string;
4+
type ConversionCustom = 'as-number' | 'as-text';
5+
16
function combine(
2-
n1: number | string,
3-
n2: number | string,
4-
resultConversion: 'as-number' | 'as-text', // ์ด๋ ‡๊ฒŒ ํƒ€์ž…์„ ์ง€์ •ํ•  ์ˆ˜๋„ ์žˆ์ง€๋งŒ ๋ฆฌํ„ฐ๋Ÿด ํƒ€์ž…์„ ์ง์ ‘ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.
7+
n1: Combinable,
8+
n2: Combinable,
9+
resultConversion: ConversionCustom,
510
) {
611
let result;
712
if (typeof n1 === 'number' && typeof n2 === 'number' || resultConversion === 'as-number') {
8-
result = +n1 + +n2; //error ts(2365) -> n1, n2์™ธ ๋‹ค๋ฅธ ์ธ์ž ์ถ”๊ฐ€๋˜๋ฉด์„œ ์กฐ๊ฑด๋ฌธ์—์„œ์˜ ๋…ผ๋ฆฌ์  ํ๋ฆ„์ด ์ถฉ๋ถ„ํžˆ ๋ช…ํ™•ํ•˜์ง€ ์•Š์•„ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๋‹ค. ๋”ฐ๋ผ์„œ ์ด ์ฝ”๋“œ์—์„œ TypeScript๋Š” n1๊ณผ n2๊ฐ€ string ํƒ€์ž…์ผ ๊ฐ€๋Šฅ์„ฑ์ด ์žˆ๋‹ค๊ณ  ํŒ๋‹จ, ์ธ์ž๋“ค์„ ์‚ฌ์šฉํ•  ๋•Œ ๋” ๋ช…ํ™•ํ•œ ํƒ€์ž…์„ ์š”๊ตฌ ๋”ฐ๋ผ '+'๋ฅผ ์ถ”๊ฐ€ํ•จ, ์ด๋Š” ๋ฆฌํ„ฐ๋Ÿด ํƒ€์ž…๊ณผ๋Š” ๋ฌด๊ด€ํ•˜๋‹ค.
13+
result = +n1 + +n2;
914
} else if (typeof n1 === 'string' && typeof n2 === 'string') {
1015
result = n1 + n2;
1116
} else {
@@ -17,7 +22,7 @@ function combine(
1722
// return result.toString();
1823
// }
1924
}
20-
// ๋ฆฌํ„ฐ๋Ÿด ํƒ€์ž…์ด๋ž€? ๋ฆฌํ„ฐ๋Ÿด ํƒ€์ž…์€ ํŠน์ • ๋ณ€์ˆ˜๋‚˜ ์–ด๋–ค ํƒ€์ž…์ด์–ด์•ผ ํ•˜๋Š”์ง€ ์ •์˜ํ•˜๋Š”๊ฒŒ ์•„๋‹ˆ๋‹ค. ๋‹จ์ง„ ์ •ํ™•ํžˆ ์–ด๋–ค ๊ฐ’์ธ์ง€ ์ •์˜ํ•˜๋Š” ๊ฒƒ์ด๋‹ค. ์ด๋ฅผ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ๋งˆ์šฐ์Šค๋ฅผ ์›ํ•˜๋Š” ๊ฐ’์— ํ˜ธ๋ฒ„ํ•˜๋ฉด ๋ฐ˜ํ™˜๋˜๋Š” ๊ฐ’์ด ๋ฌด์—‡์ธ์ง€ ํ™•์ธ์ด ๋œ๋‹ค. Ts๋Š” ์•Œ์•„๊ฐˆ ์ˆ˜๋ก ์ ์  ํƒ€์ž…๋“ค์„ ๊ตฌ์ฒด์ ์œผ๋กœ ์ขํ˜€๊ฐ€๋Š” ๊ฒƒ์œผ๋กœ ๋ณด์ธ๋‹ค.
25+
2126
const combineAges = combine(20, 30, 'as-number');
2227
console.log(combineAges);
2328

0 commit comments

Comments
ย (0)