title: typescript - object is possibly 'null'
body: <p>I get this error for the following but the program running perfectly</p>
  
  <p><a href="https://i.stack.imgur.com/4NQyR.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/4NQyR.jpg" alt="error"></a></p>
  
  <pre><code>var video = document.querySelector('#camera-stream'),
  
  if(!navigator.getMedia){
          displayErrorMessage("Your browser doesn't have support for the navigator.getUserMedia interface.");
      }
      else{
          // Request the camera.
          navigator.getMedia(
              {
                  video: true
              },
              // Success Callback
              function(stream:any){
  
                  // Create an object URL for the video stream and
                  // set it as src of our HTLM video element.
                  video.src = window.URL.createObjectURL(stream);
  
                  // Play the video element to start the stream.
                  video.play();
                  video.onplay = function() {
                      showVideo();
                  };
  
              },
              // Error Callback
              function(err:any){
                  displayErrorMessage("There was an error with accessing the camera stream: " + err.name, err);
              }
          );
  
      }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/5tkvX.png" alt="example error "></p>
  
  <p>I tried the solution <a href="https://stackoverflow.com/questions/40349987/how-to-suppress-typescript-error-ts2533-object-is-possibly-null-or-undefine">in this questions</a> but didn't work for me.</p>
  
  <p>What is the proper fix for this error?</p>