//변수에 type 넣어서 사용하기 (type Alias)
//PascalCase로 타입이름을 지정하는 게 국룰
type Animal = string|number|undefined
type Animal2 = {name:string, age:number};
const 동물 : Animal = '스트링/넘버/언디' ;
const 동물2 : Animal2 = {name:'강아지', age:2}
//reference data type 락걸기 (ts파일 안에서만 그럼)
type Gf = {readonly name:string, age:number} // type에 readonly라고 지정해주면, 내부 수정이 불가능하다.
const 여친:Gf = {name : '경아', age:30};
// 여친.name = '누군가'; // 불가능하다. (에러만 띄워준다. 실제 실행은 상관업따요)
// type 키워드 합치기 (or)
type Name = string;
type Age = number;
type Person = Name|Age;
// type 키워드 extend (and)
type PositionX = { x : number }
type PositionY = { y : number }
type AllPosition = PositionX & PositionY ;
const nowPosition:AllPosition = {x: 10, y:20};
//type 키워드는 재정의가 불가능하다.
댓글