[TypeScript] Type Aliases


1. Type Aliases : μ›ν•˜λŠ” νƒ€μž…μ„ μ§€μ •ν•˜λŠ” 것

1. λ³€μˆ˜μ²˜λŸΌ νƒ€μž…μ˜ 별λͺ…을 μ§€μ–΄μ€Œ

type Text = string;

const name: Text = 'kdn';
const address: Text = 'korea'

2. 객체에 λ“€μ–΄κ°ˆ νƒ€μž…μ„ μ§€μ •ν•΄μ€Œ

type Student = {
    name:string;
    age:number;
}

const student: Student ={
    name:'kdn',
    age:12,
}
  • String Literal Types : κ°’ 자체λ₯Ό νƒ€μž…μœΌλ‘œ μ§€μ •ν•˜λŠ” 것
type JSON = "json";
const json: JSON = "json";

console.log("json?", json);