SweetAlert with Angular 7

Paraskevas Louka picture Paraskevas Louka · Feb 26, 2019 · Viewed 8.8k times · Source

I am trying to use sweet alert in my angular project.

That's how I use sweet alert:

import swal from 'sweetalert';

swal({
    title: "Problem",
    text: "Try again later!",
    icon: "error"
  })

I get the following error:

ERROR in node_modules/sweetalert/typings/sweetalert.d.ts(4,9): error TS2403: Subsequent variable declarations must have the same type. Variable 'swal' must be of type 'typeof import("C:/Users/user/Desktop/University/Thesis/workspace/web/myProject/project/node_modules/sweetalert/typings/sweetalert")', but here has type 'SweetAlert'.

Anyone can help me with that?

Answer

OmkieIT Solutions picture OmkieIT Solutions · Jun 15, 2019

The simple solution to compile the Angular project is Go to your project folder \node_modules\sweetalert\typings\sweetalert.d.ts

In this file simply comment the line // const swal: SweetAlert;

and your final file looks like this:

import swal, { SweetAlert } from "./core";

declare global {
  // const swal: SweetAlert;
  const sweetAlert: SweetAlert;
}

export default swal;
export as namespace swal;