Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 정보처리기사 실기
- TS
- JavaScript
- 정보처리기사
- 큐넷
- spring boot security
- Redux
- 타입스크립트
- Authentication
- Node.js
- spring
- spring boot
- 웹개발자
- VUE
- It
- frontend
- JWT
- 수제비
- Front-End
- 스프링부트
- 백엔드
- useState
- JS
- 프론트엔드
- 백엔드개발자
- 리액트
- TypeScript
- React
- 자바스크립트
- security
Archives
- Today
- Total
솔적솔적
Typescript Object에 쓸 수 있는 interface_part5 본문
type 키워드를 이용해서 타입변수를 생성할 수 있었지만 interface로도 interface 키워드도 변수 생성이 가능합니다.
type키워드를 이용한 변수 생성
type person = { name : string , age : number}
let 솔 : person - { name : 'park', age : 12}
interface키워드를 이용한 변수생성
interface person = {name : string , age : number}
let 솔 : person = {name :'park', age : 12}
엥 똑같은데 인터페이스를 왜 써?
extends가 가능하기 때문이다.
interface person {
name :string
age : number
}
interface animal{
name : string
age : number
color : black
}
let 사람 : person = { name : 'park' age = 12}
let 동물 : animal = { name : 'mongmong' age = 1}
중복되어있는 것들을 복사
interface person {
name :string
age : number
}
interface animal extends person{
color : black
}
let 사람 : person = { name : 'park' age = 12}
let 동물 : animal = { name : 'mongmong' age = 1}
& 기호 (intersection type) 이런 식으로 가능하다.
type person = {name : string }
type man = { age : number } & person
이제 man은 age와 person 의 속성을 갖게 된다.
여기서 인터페이스와 타입에 대한 차이를 더 짚는다면
인터페이스는 중복선언이 가능 vs 타입은 중복 선언이 불가능하다.
interface person {
name : string
}
interface person {
eat : string
}
interface animal extends person{
color : black
}
인터페이스는 이렇게 중복 선언을 해도 에러없이 속성이 들어가지만
type person = {name : string }
type person = {eat : string } //둘 다 에러남
타입은 중복 선언 시 에러가 난다.
'Front-end > typesrcipt' 카테고리의 다른 글
Typescript Narrowing 타입 사용할 때 주의😈 (0) | 2022.01.21 |
---|---|
Typescript rest parameter / destructuring일 때 타입지정은?_part6 (0) | 2022.01.21 |
Typescript 내가 너의 것을 딱 정해줄게 Literal타입 PART4 (0) | 2022.01.16 |
Typescript 타입을 변수에 쏙 part3 (0) | 2022.01.16 |
Typescript 애매할 때 딱 잡아바꾸자!(narrowing과 Assertion) Part2 (0) | 2022.01.16 |