DEV Community

irisha1313
irisha1313

Posted on

error ts(2345)

argument of type 'htmlelement | null' is not assignable to parameter of type 'element'. type 'null' is not assignable to type 'element'. ts(2345)

import.js

import React from 'react';
import { createRoot } from 'react-dom/client';
import './index.css';
import App from './App';

const container = document.getElementById('root')
const root = createRoot(container)
root.render(<App />)
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
joelbonetr profile image
JoelBonetR 🥇

It's probably thinking that document.getElementById can be either an htmlelement or null (if it can't find that identifier in the DOM) so it fails in createRoot trying to ensure what you send to it is effectively an element.