Argument of type ‘HTMLElement | null’ is not assignable to parameter of type ‘Element’. Type ‘null’ is not assignable to type ‘Element’.ts(2345)

Other people have answered that you should add a null-check, but Typescript also has a non-null assertion that you can use when you are sure that the value is never null by adding the ! operator to the end of your statement:

const portalDiv = document.getElementById('your-element')!;

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)