[TIL] 220625 91일차

youngseo·2022년 6월 24일
0

TIL

목록 보기
90/121
post-thumbnail

91일차

  • 그룹과제
    • 구현한 기능들 팀 폴더에서 차근차근 다시 구현해보기
  • 타입스크립트 복습

새로배운 내용

타입단언

const el = document.querySelector('.close')

console.log(el.textContent)

만약 close라는 클래스가 붙은 요소가 없다면 null.texContext로 에러가 발생하게 됩니다. 이런 부분을 보완할 수 있는 타입 단언이 잇습니다.

  1. val as T
  2. <T> val
  3. Null-nun 단언연산자
const el = document.querySelector('close')

console.log((el as HTMLElement).textContent)
console.log(el!.textContent)

타입가드


if(el){
  console.log(el.textContent)
}

0개의 댓글