πŸ“’[TypeScript λ§ˆμŠ€ν„° with Webpack & React] Step06.Tupleκ³Ό Enum

κΆŒμš©μ€€Β·2023λ…„ 12μ›” 6일
0
post-thumbnail

1. νŠœν”Œ κ°œμš”

λ°°μ—΄ νƒ€μž…μ΄μ§€λ§Œ 길이와 νƒ€μž…κ³Ό λ°°μ—΄ μˆœμ„œκ°€ κ³ μ •λœλ‹€.


let myTuple: [number, string] = [2342, "mytuple"];

2. νŠœν”Œ 더 μ•Œμ•„λ³΄κΈ°


type HTTPResponse = [number : string];

const goodRes: HTTPResponse = [200, "OK"]; // 1. νŠœν”Œμ€ μƒμ„±λœ μ‹œμ μ—λ§Œ κ·œμΉ™μ„ λ”°λ₯Έλ‹€

const responses: HTTPResponse[] = [[404,"Not Found"], [200, "OK"]];

goodRes[0] = "200"; // compile 2. μ„€μ •ν•œ νƒ€μž…μ΄ μ•„λ‹ˆμ—¬λ„ μƒμ„±λœ μ‹œμ  이후에 μ‘°μž‘ν•˜λ©΄ compile이 λœλ‹€.
goodRes.push(123); // compile
goodRes.pop(); // compile

3. Enum

Enum은 λͺ…λͺ…λœ μƒμˆ˜ 집합을 μ •μ˜ν•  수 μžˆλ‹€.
μ½”λ“œ μ „μ²΄μ—μ„œ μž¬μ‚¬μš©ν•  수 μžˆλŠ” λͺ…λͺ…λœ μƒμˆ˜μ˜ 집합이닀.
ν•œ 묢음의 이름을 enum에 μ§€μ •ν•˜λ©΄ κ³„μ†ν•΄μ„œ μ°Έμ‘°κ°€ κ°€λŠ₯ν•˜κ³  νŽΈλ¦¬ν•˜κ²Œ μžλ™ μ™„μ„± κΈ°λŠ₯도 μ‚¬μš©κ°€λŠ₯ν•˜λ‹€.


enum OrderStatus {
PENDING,
SHIPPED,
DELIVERED,
RETURNED,
}
const myStatus = OrderStatus.DELIVERD;

function isDelivered(status: OrderStatus){
return status === OrderStatus.DELIVERED;
}

isDelivered(OrderStatus.RETURNED);

profile
Brendan Eich, Jordan Walke, Evan You, κΆŒμš©μ€€

0개의 λŒ“κΈ€