我正在使用甜蜜警报库:
https://limonte.github.io/sweetalert2/
我正在尝试使用网站上的以下代码:
swal({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!',
cancelButtonText: 'No, cancel!',
confirmButtonClass: 'btn btn-success',
cancelButtonClass: 'btn btn-danger',
buttonsStyling: false
}).then(function () {
swal(
'Deleted!',
'Your file has been deleted.',
'success'
)
}, function (dismiss) {
// dismiss can be 'cancel', 'overlay',
// 'close', and 'timer'
if (dismiss === 'cancel') {
swal(
'Cancelled',
'Your imaginary file is safe :)',
'error'
)
}
})
我已经通过运行以下命令安装了类型:
npm install --save @types/sweetalert
但我仍然收到与使用"then"有关的错误消息:
error TS2339: Property 'then' does not exist on type 'void'.
我该如何解决此问题?
我认为您的类型定义文件和库加起来并不多。您已经拉入了@types/sweetalert
,这是https://sweetalert.js.org/
的 .d.ts 文件,而不是 https://limonte.github.io/sweetalert2/
。
查看 SweetAlert2 的存储库,它包含与库相同的 npm 包中的类型定义。