일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 투포인터
- React
- 인터섹션
- 태그된 유니온
- Jest
- async/await
- 무한 스크롤
- CI/CD
- app router
- CORS
- 호이스팅
- map
- Promise
- SSR
- tailwind
- 결정 알고리즘
- recoil
- dfs
- 이분 검색
- useAppDispatch
- 리터럴 타입
- Cypress
- RTK Query
- 반공변성
- 공변성
- ESlint
- autosize
- webpack
- 타입 좁히기
- TS
- Today
- Total
목록리터럴 타입 (2)
짧은코딩
재귀 타입 TS에는 자기 자신을 다시 사용하는 재귀 타입이 있다. type Recursive = { name: string; children: Recursive[]; }; const recur1: Recursive = { name: 'test', children: [{ name: 'test2', children: [] }], }; 이렇게 recur1은 Recursive 객체 속성 타입으로 다시 Recursive를 사용한다. 이런 것을 바로 재귀 타입이라고 부른다. -컨디셔널 타입 type ElementType = T extends any[] ? ElementType : T; 이런식으로 컨디셔널 타입에서도 사용 가능하다. 다만, 이렇게 재귀 타입을 잘못 사용하면 자기 자신을 계속 가져오는 상황에 빠질 수 ..
never 타입 const x: never = 12; never는 공집합이라는 의미라서 아무런 값도 할당할 수 없다. 따라서 x에 12를 넣을 수 없다. 유닛(unit) 타입/리터럴(literal) 타입 type A = 'A'; type B = 'B'; type Twelve = 12; 유닛 타입은 never 다음으로 작은 집합이며 한 가지 값만 포함하는 타입이다. 유니온(union) 타입 type AB = 'A' | 'B'; type AB12 = 'A' | 'B' | 12; 유니온 타입은 값 집합들의 합집합이다. "|"을 사용해서 타입을 묶어줄 수 있다. -예시 const a: AB = "A"; // 정상 const c: AB = "C"; // "C"는 'AB' 형식에 할당할 수 없다. "C"는 유닛 타..