๋ฐ์ํ
React์์ typescript๋ก ๊ฐ๋ฐํ๋๋ฐ ์๋์ ์๋ฌ๊ฐ ๋ฐ์ํ๋ค.
const root = ReactDOM.createRoot(document.getElementById("root"));
์๋ฌ ๋ด์ฉ์ ์๋์ ๊ฐ์๋ค.
Argument of type 'HTMLElement | null' is not assignable to parameter of type 'Element | DocumentFragment'.
Type 'null' is not assignable to type 'Element | DocumentFragment'.
ํด๊ฒฐ ๋ฐฉ๋ฒ์ ๊ฐ๋จํ๋ค. getElementById๋ฅผ ํตํด ๋ฐ์์ค๋ ๊ฐ์ฒด์ Type์ ์ง์ ํด์ฃผ๋ฉด ๋๋ค. TypeScript๊ฐ ๋ฐ์ดํฐ ํ์ ์ ์์๋ณผ ์ ์๋๋ก ํด์ฃผ๋ ๊ฒ. ์์ ๋ ์ฝ๋๋ ์๋์ ๊ฐ๊ณ , ํต์ฌ์ as HTMLElement ๋ค.
const root = ReactDOM.createRoot(
document.getElementById("root") as HTMLElement
);
๋ค์ ๊ฐ๋ฐ์ ํ๋ฌ ๋ค์ ๋์๊ฐ๋ณด๊ฒ ๋ค. ๊ทธ๋ผ 20000
๋ฐ์ํ
๋๊ธ