728x90
Array
const fruits: string[] = ['사과', '바나나'];
const scroes: Array<number> = [1, 3, 4];
function printArray(fruits: readonly string[]) {}
- Type[] 방법
- Array 방법
- readonly Type을 변경하지 못하도록 하기
Tuple -> interface, type alias, class
let student: [string, number];
student = ['name', 123];
student[0]; // name
student[1]; // 123
const [name, age] = student;
- 서로다른 Type이 있을 때 사용한다.
- Tuple 사용을 권장하지 않는다.
- 가독성이 너무 않좋고 어떤 데이터가 들어갔는지 확인 방법이 번거롭다
- interface, type alias, class 주로 사용한다
'Node > TypeScript' 카테고리의 다른 글
7.Union (0) | 2021.04.17 |
---|---|
6.Aliases (0) | 2021.04.15 |
4.함수 타입(JS →TS) (0) | 2021.04.15 |
3.기본 타입(2) (0) | 2021.04.14 |
2. 기본 타입(1) (0) | 2021.04.14 |
댓글