Property 'done' does not exist on type 'object' .ts
타입 정의 하기 function completeTodo(index:number, todo:{ id: number, title: string, done: boolean, }): void { todo.done = true; todoItems.splice(index, 1, todo); } 타입 정의 let todoItems: { id: number, title: string, done: boolean }[]; function completeTodo(index:number, todo:{ id: number, title: string, done: boolean, }): void { todo.done = true; todoItems.splice(index, 1, todo); } 중복되는 코드를 줄이고 타입을 하나로..
2023. 12. 24.
타입스크립트_기본타입, interface
Typescript function showTimes(arr) { arr.forEach(element => { console.log(element) }); } showTimes([1,2,3]) //1, 2, 3 showTimes(1,2,3) //error 발생 Javascript(동적언어): 실행되는 시점 (런타임)에 타입이 결정되고 오류가 있을 시 그때 처리가 가능하다. function showTimes(arr:number[]) { arr.forEach(element => { console.log(element) }); } showTimes([1,2,3]) //1, 2, 3 function showTimes(arr:string[]) { arr.forEach(element => { console.log(..
2022. 11. 30.