본문 바로가기
Frontend/TypeScript(완)

[TS] TS연습하기6

by VictorMeredith 2023. 4. 12.

// Rest Parameter의 타입 지정
const resParams = (...a:string[]):void => { //파라미터에 ...a 이렇게 점을 붙여주면 파라미터가 여러개 올 수 있다.
  console.log(a)
}
resParams('a','b','c','d');

//destructuring 문법에서의 type 
const 옵젝트 = {student : true, age : 20}
const 하암수 = ({student, age}:{student:boolean, age:number}):void=>{
  console.log(student, age)
}
하암수(옵젝트)

//숫자를 여러개 입력하면 최대값을 return 해주는 함수 ? Math.max 사용금지
const 숫자여러개 = (...a:number[]):number => {
  let now:number = 0;
  [...a].forEach(e => {
    if(now<e){
      now = e
    }
  })
  return now;
}
console.log(숫자여러개(1,3,6,7,8,4,21,56,7,68,4,357,356,6,3565,36,3,25,13,7,45,7))

//숙제 객체
type 숙제타입 = {user:string, comment: number[], admin : boolean};
const 숙제객체:숙제타입 = {user:'kim', comment :[3,4,5], admin : false}
const 숙제함수 = ({user, comment, admin}:숙제타입):void => {
  console.log(user, comment, admin)
}
숙제함수(숙제객체);

 

'Frontend > TypeScript(완)' 카테고리의 다른 글

[TS] TS연습하기8  (0) 2023.04.12
[TS] TS연습하기7  (0) 2023.04.12
[TS] TS연습하기5  (0) 2023.04.12
[TS] TS연습하기4  (0) 2023.04.12
[TS] TS 연습하기3  (0) 2023.04.12

댓글