붉은거위 노트 (redgoose note)

타입스크립트(Typescript) 노트

Nest
Development
Category
Javascript
Hit
42
Star
0

document.querySelector() 메서드 사용하기

다양한 엘리먼트 타입으로 선언되기 때문에 타입을 따로 추론을 해줘야 한다. 그냥 메서드를 사용하니 경고가 나오는데 다음과 같이 해결할 수 있다.

const $root = document.querySelector('#root') as HTMLElement
console.log($root)

출처: https://bobbyhadz.com/blog/typescript-queryselector