Skip to content

Commit b8229cf

Browse files
committed
๐Ÿšฉ: ํ•จ์ˆ˜ void์™€ never ์‚ฌ์šฉ ๋ฐฉ๋ฒ•
1 parent 091f3c7 commit b8229cf

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

โ€Žsrc/index.tsโ€Ž

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
// ํŠœํ”Œ ํƒ€์ž… ์ง€์ • ๋ฐฉ์‹
1+
//ํ•จ์ˆ˜ void, never
22

3-
//์ฒซ ๋ฒˆ์งธ ์ธ์ž๋Š” string, ๋‘ ๋ฒˆ์งธ ์ธ์ž๋Š” number
4-
let b: [string, number];
3+
//void: void๋Š” ๋ฐ˜ํ™˜๋˜๋Š” ๊ฐ’์ด ์—†์„ ๋•Œ์ด๋‹ค.
4+
function sayHello(): void {
5+
console.log('hello');
6+
}
57

6-
b = ['z', 3];
7-
// b = [3, '3']; //-> error
8+
//never : never๋Š” ํ•ญ์ƒ error๋ฅผ ๋ฐ˜ํ™˜ํ•˜๊ฑฐ๋‚˜ ์˜์›ํžˆ ๋๋‚˜์ง€ ์•Š๋Š” ๋ฌดํ•œloop์ผ ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค.
9+
function showError(): never {
10+
throw new Error();
11+
}
812

9-
b[0].toLowerCase();
10-
// b[1].toLowerCase(); //-> error: ์ˆซ์ž์—๋Š” ๋Œ€/์†Œ๋ฌธ์ž๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์—†๋‹ค.
13+
function infLoop(): never {
14+
while (true) {
15+
//do something...
16+
}
17+
}

0 commit comments

Comments
ย (0)