[내일배움캠프 TIL] 58일차

Jaehyeon Ye·2023년 1월 19일
0

오늘 새로 배운 것

인덱스 시그니처 매개 변수 형식은 'string', 'number', 'symbol' 또는 템플릿 리터럴 형식이어야 합니다.

예:

interface Todos {
  id: string | number;
  title: string | number;
  content: string | number;
  isDone: boolean;
  [other: string]: any;
}

other라는 key의 타입에 string, number, symbol, Template literal 타입이 아닌 any같은 다른 타입을 선언하면 에러가 난다.

narrowing

<h1 id='title'>내용</h1>
let tagTitle = document.querySelector('#title')
if(tagTitle != null){ //narrowing
  tagTitle.innerHTML = '바꿀 내용'
}

 // narrowing 방법2
 if(tagTitle instanceof Element){
 	tagTitle.innerHTML = '바꿀 내용'
 }

// narrowing 방법3 (확실할 때 아니면 권장하지 않음)
let tagTitle = document.querySelector('#title') as Element;

// narrowing 방법4 옵셔널 체이닝

useNavigate에서 replace

replace: true가 window.location.replace의 역할을 함

const navigate = useNavigate();

navigate('/', { replace: true }
profile
FE Developer

0개의 댓글