Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SweetAlert with Angular 7

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?

like image 937
Paraskevas Louka Avatar asked Feb 26 '19 15:02

Paraskevas Louka


2 Answers

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;
like image 192
OmkieIT Solutions Avatar answered Oct 10 '22 06:10

OmkieIT Solutions


I had the same issue, my solution was this.

import * as _swal from 'sweetalert';
import { SweetAlert } from 'sweetalert/typings/core';

const swal: SweetAlert = _swal as any;

for some reason the name "swal" show error, if you change alias by "_swal" it should work

like image 33
Gerardo Cetzal Avatar answered Oct 10 '22 04:10

Gerardo Cetzal