μλ‘μ΄ νμ μ μ¬μ©μκ° μ μν μ μλ€.
type Name = string;
const yourName: Name = "Joanna";
console.log(yourName);
//Joanna
alias νμ μ μ§μ ν λλ typeμ΄λΌλ ν€μλλ₯Ό μμ μμ±νκ³ Typeμ μ΄λ¦μ λλ¬Έμλ‘ μμνλ€.
μμν νμ λΏλ§ μλλΌ μ°Έμ‘°νμΈ κ°μ²΄λ κ°λ₯νλ€.
type Student = {
name: string;
age: number;
};
const student: Student = {
name: "Joanna",
age: 12
}
Student typeμΌλ‘ μ§μ λ λ³μλ λ°λμ ν€ κ°μ΄ λμΌν΄μΌ νλ€.
const student: Student = {
lastName: "Joanna", //error
years: 12. //error
}
ν€ κ°μ nameκ³Ό ageλ§ μμ±ν μ μλ€.