728x90
반응형
- 참고 링크 :
Documentation - Everyday Types
The language primitives.
www.typescriptlang.org
공통점
타입스크립트에게 오브젝트의 모양과 타입을 알려주기 위함
차이점
1. 타입은 새 property를 추가하기 위해 재선언이 불가하지만 interface는 가능
2. 상속 방법
타입 상속
type PlayerA = {
firstName : string,
lastName : string
}
type PlayerAA = PlayerA & {
age : number
}
const playerA : PlayerAA = {
firstName : "a",
lastName : "b",
age : 10
}
인터페이스 상속
interface PlayerB {
firstName : string,
lastName : string
}
interface PlayerBB extends PlayerB {
age : number
}
const playerB : PlayerBB = {
firstName : "B",
lastName : "bb",
age: 11
}
728x90
'Frontend > TypeScript' 카테고리의 다른 글
[TypeScript] 다형성 (Polymorphism) (0) | 2023.02.10 |
---|---|
[TypeScript] VSC 타입스크립트 설치 및 설정 방법 (0) | 2023.02.01 |
[TypeScript] 인터페이스 (Interface) (0) | 2023.01.30 |
[TypeScript] 클래스, 추상 클래스, 추상 메소드 (Classes, Abstract Classes, Abstract Method) (0) | 2023.01.29 |
[TypeScript] 제네릭 (Generic) (0) | 2023.01.28 |