Home > Software engineering >  Object is possibly 'null' Typescript
Object is possibly 'null' Typescript

Time:09-19

I seem to have encountered an issue where it tells me that the object's are possibly null. I have looked online and on StackOverflow and tries a dozen fixes to no success. I am trying to insert the text "test" into the html elements using their id's.

  var cname = document.getElementById("chargername");
  var cloc = document.getElementById("chargerlocation");
  var ctype = document.getElementById("chargertype");
  var cdesc = document.getElementById("chargerdescription");
  var crating = document.getElementById("chargerrating");

  function handleClick() {
    cname.innerHTML = "test";
    cloc.innerHTML = "test";
    ctype.innerHTML = "test";
    cdesc.innerHTML = "test";
    crating.innerHTML = "test";
  }

I get this error: "TypeError: Cannot set properties of null (setting 'innerHTML')"

Any help is appreciated, Thanks!

  • Related