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?
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;
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With