all is well!!

11. [Ts] Tuple 본문

항상 정해진 갯수의 요소를 가져야하는 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

Comments