title: How to call javascript alert in a typescript component
body: <p>I am trying to call a custom javascript alert in typescript. The problem is that I can't use "this" keyword in javascript and typescript code does not wait for javascript function to finish.</p>
  
  <p>What I am saying is:</p>
  
  <pre><code>declare var $: any;
  declare var swal: any;
  
  ...
  
  
      delete(id: number) {
  
          var toDeleteOrNot: boolean = false;
  
          swal({
              title: "Are you sure?",
              text: "You will not be able to recover this imaginary file!",
              type: "warning",
              showCancelButton: true,
              confirmButtonColor: "#DD6B55",
              confirmButtonText: "Yes, delete it!",
              cancelButtonText: "No, cancel plx!",
              closeOnConfirm: false,
              closeOnCancel: false
          }, function (isConfirm: boolean) {
              if (isConfirm) {
                  toDeleteOrNot = true;
                  swal("Deleted!", "Your imaginary file has been deleted.", "success");
              } else {
                  swal("Cancelled", "Your imaginary file is safe :)", "error");
              }
              });
  
          if (toDeleteOrNot) {
              this.getagentiiService.deleteAgentie(id).subscribe(x =&gt; {
                  this.populateAgentii();
              });
          }
      }
  </code></pre>
  
  <p>The function(swal) and the "if" are called at the same time. Var toDeleteOrNot in if maintains its initialization value(in this case it is false). I can't move the "if" inside the javascript because it gives </p>
  
  <pre><code>'this' implicitly has type any because it does not have a type annotation
  </code></pre>
  
  <p>How can I use this custom javascript function inside typescript?</p>