[TypeScript] Type Aliases
μΉ΄ν
κ³ λ¦¬ : νλ‘κ·Έλλ° μΈμ΄
νκ·Έ: ts · typescript · Type Aliases · Literal Types · String Literal Types
νκ·Έ: ts · typescript · Type Aliases · Literal Types · String Literal Types
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);