all is well!!
11. [Ts] Tuple 본문
[Nextjs + Typescript] velog 클론코딩/[ Nextjs + Typescript ] 나를 위한 기록
11. [Ts] Tuple
tnqlscho 95 2023. 2. 22. 23:58항상 정해진 갯수의 요소를 가져야하는 array를 지정.
const player: [string, number, boolean] = [‘subin’, 1, true]
배열안에 각 요소들의 type을 정해주면 이 type의 순서도 지켜야한다.
const player: [string, number, boolean] = [‘subin’, ture, 1] -> error
이렇게 player[1]과 player[2]의 값이 바뀌면 에러가 난다.
const player: readonly [string, number, boolean] = [‘subin’, 1, true]
readonly와 tuple을 같이 쓸수있다.
*출처 [노마드코더 ts 강의]
https://nomadcoders.co/typescript-for-beginners/lectures/3671
'[Nextjs + Typescript] velog 클론코딩 > [ Nextjs + Typescript ] 나를 위한 기록' 카테고리의 다른 글
| 13. [Ts] readonly (0) | 2023.02.24 |
|---|---|
| 12. [Ts] unknown, void, never (0) | 2023.02.23 |
| 10. 산술 연산의 왼쪽은 'any', 'number', 'bigint' 또는 열거형 형식이어야 합니다. (0) | 2023.02.17 |
| 9. ''의 형식의 인수는 ''형식의 매개 변수에 할당될 수 없습니다. (0) | 2023.02.15 |
| 8. typescript - redux toolkit 써보기(+보일러 플레이트) (0) | 2023.02.14 |
Comments