λ°°μ΄ νμ μ΄μ§λ§ κΈΈμ΄μ νμ κ³Ό λ°°μ΄ μμκ° κ³ μ λλ€.
let myTuple: [number, string] = [2342, "mytuple"];
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
Enumμ λͺ
λͺ
λ μμ μ§ν©μ μ μν μ μλ€.
μ½λ μ 체μμ μ¬μ¬μ©ν μ μλ λͺ
λͺ
λ μμμ μ§ν©μ΄λ€.
ν λ¬Άμμ μ΄λ¦μ enumμ μ§μ νλ©΄ κ³μν΄μ μ°Έμ‘°κ° κ°λ₯νκ³ νΈλ¦¬νκ² μλ μμ± κΈ°λ₯λ μ¬μ©κ°λ₯νλ€.
enum OrderStatus {
PENDING,
SHIPPED,
DELIVERED,
RETURNED,
}
const myStatus = OrderStatus.DELIVERD;
function isDelivered(status: OrderStatus){
return status === OrderStatus.DELIVERED;
}
isDelivered(OrderStatus.RETURNED);