다른 변수처럼 (var, let, const처럼 이건 type)
type Animal = string | number | undefined;
type Animal2 = { name: string; age: number };
let 동물: Animal = "kim";
let 동물2: Animal2 = { name: "kim", age: 20 };
readOnly
type GirlFriend = {
readonly name?: string; //실수로 수정하면 에러내줌
};
// 여친.name = "유라"; 에러뜸.
합치기, extend
type Name = string;
type Age = number;
type Person = Name | Age;
type PositionX = { x: number };
type PositionY = { y: number };
type NewType = PositionX & PositionY;
let Position: NewType = { x: 10, y: 20 };