Front-end/Typescript (3) 썸네일형 리스트형 type vs interface 차이점 1. 확장하는 방법 // interface interface PeopleInterface { name: string age: number } interface StudentInterface extends PeopleInterface{ school: string } // type type PeopleType = { name: string age: number } type StudentType = PeopleType & { school: string } 2. 선언적 확장 interface에서 할 수 있는 대부분의 기능은 type에서 가능 type은 새로운 속성을 추가하기 위해 같은이름으로 선언할 수 없음 interface는 항상 선언적 확장이 가능 // interface interface window.. Enum 정의 enum(열거형)을 사용하여 상수 집합을 정의할 수 있음 enum을 사용하면 의도를 문서화 하거나 별개의 사례 집합을 더 쉽게 만들 수 있음 numeric enums enum Direction { Up = 1, Down, Left, Right, } Up 은 1로 초기화 됨 나머지 초기화 되지 않은 멤버들은 auto-increment가 적용됨 Down = 2 Left = 3 Right = 4 enum Direction { Up, Down, Left, Right, } 초기화가 없을시 첫 멤버(Up)가 0으로 초기화됨 나머지는 auto-increment됨 Down = 1 Left = 2 Right = 3 auto-increment 동작은 멤버의 value가 중요하지 않지만 구별이 필요할때 유용함 Stri.. Typescript Core 기본 문법 1. 타입 주석 / 타입 추론 let n: number = 1 // type annotation let m = 2 // type interface 2. interface // 'Person'이라는 인터페이스를 생성. // Person은 name은 반드시 정의되어야 하며, // age는 optional(?)로 age를 가질 수 있지만 null, undefined가 허용된다. interface Person { name: string// 반드시 정의되어야 한다. age?: number// optional } // 'person'이라는 변수는 인터페이스에 의해 'Person'타입이다. name을 반드시 정의해야한다. let person: Person = {name: "Jane"} 3. tuple //.. 이전 1 다음