?연산자

TypeScript

Tuple type

Tuple 타입 let 멍멍: (string | boolean)[] = ["dog", true]; //union타입 let 야옹: [string, boolean] = ["cat", true]; //tuple타입 let 야옹2: [boolean, string] = ["cat", true]; //tuple타입 에러발생 [ ] 괄호 안에 타입을 적으면 tuple 타입이 된다. 첫 자료는 string, 둘째 자료는 boolean 타입처럼 위치까지 구체적으로 지정하려면 tuple을 사용하면 된다. => 예시를 보면 야옹 2는 자료위치와 타입선언이 맞지 않아 에러가 발생한 것. Tuple + rest parameter 문법 function 함수(...x: [number, string]) { console.log(x..

www.seok.com
'?연산자' 태그의 글 목록