无法在打字稿上设置 sweetalert 选项
Can't set sweetalert options on typescript
已安装的软件包:
"@angular/core": "^4.0.0"
"typescript": "~2.3.3"
"sweetalert": "^2.0.8"
"@types/sweetalert": "^1.1.28"
我如何使用 sweetalert:
import * as swal from "sweetalert";
//...
doSomething() {
const options = {
title: "Are you sure?",
text: "Some text here!",
type: "warning",
showCancelButton: true,
showConfirmButton: true
};
swal(options, (remove) => { });
}
我遇到了这些错误:
- VSC 智能感知:
'Argument of type '{ title: string; text: string; type: string;
showCancelButton: boolean; showConfirmButton: boolea...' is not
assignable to parameter of type 'Settings & PromtModalSettings'.
Type '{ title: string; text: string; type: string; showCancelButton:
boolean; showConfirmButton: boolea...' is not assignable to type
'PromtModalSettings'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type 'PromtType'.' at: '101,14' source: 'ts'
- TypeScript 编译,但在浏览器控制台上,我得到这个:
ERROR Error: SweetAlert: Unexpected 2nd argument (function (remove) {...
我尝试将 options
类型设置为 SweetAlert.Settings & SweetAlert.AlertModalSettings
,但我无法访问命名空间 SweerAlert
,并且还尝试了 any
。 None 他们工作了。
如何将这些选项设置为 sweetalert?
Sweetalert 不需要安装类型。它已经实施了。安装类型时,原始类型之间发生冲突,然后出现错误。我刚刚删除了 @types/sweetalert
,一切都像他们 site.
中的示例一样工作
一个简单的修复是:
直接进入项目文件夹然后\node_modules\sweetalert\typings\sweetalert。d.ts
在这里你会发现这一行
const swal: SweetAlert;
只需删除或评论它..
错误排序..
而不是搞乱 node_modules 为什么不简单地将选项转换为 SweetAlertOptions:
const options = {
title: "Are you sure?",
text: "Some text here!",
type: "warning",
showCancelButton: true,
showConfirmButton: true
} as SweetAlertOptions;
已安装的软件包:
"@angular/core": "^4.0.0"
"typescript": "~2.3.3"
"sweetalert": "^2.0.8"
"@types/sweetalert": "^1.1.28"
我如何使用 sweetalert:
import * as swal from "sweetalert";
//...
doSomething() {
const options = {
title: "Are you sure?",
text: "Some text here!",
type: "warning",
showCancelButton: true,
showConfirmButton: true
};
swal(options, (remove) => { });
}
我遇到了这些错误:
- VSC 智能感知:
'Argument of type '{ title: string; text: string; type: string; showCancelButton: boolean; showConfirmButton: boolea...' is not assignable to parameter of type 'Settings & PromtModalSettings'.
Type '{ title: string; text: string; type: string; showCancelButton: boolean; showConfirmButton: boolea...' is not assignable to type 'PromtModalSettings'. Types of property 'type' are incompatible. Type 'string' is not assignable to type 'PromtType'.' at: '101,14' source: 'ts'
- TypeScript 编译,但在浏览器控制台上,我得到这个:
ERROR Error: SweetAlert: Unexpected 2nd argument (function (remove) {...
我尝试将 options
类型设置为 SweetAlert.Settings & SweetAlert.AlertModalSettings
,但我无法访问命名空间 SweerAlert
,并且还尝试了 any
。 None 他们工作了。
如何将这些选项设置为 sweetalert?
Sweetalert 不需要安装类型。它已经实施了。安装类型时,原始类型之间发生冲突,然后出现错误。我刚刚删除了 @types/sweetalert
,一切都像他们 site.
一个简单的修复是:
直接进入项目文件夹然后\node_modules\sweetalert\typings\sweetalert。d.ts 在这里你会发现这一行
const swal: SweetAlert;
只需删除或评论它.. 错误排序..
而不是搞乱 node_modules 为什么不简单地将选项转换为 SweetAlertOptions:
const options = {
title: "Are you sure?",
text: "Some text here!",
type: "warning",
showCancelButton: true,
showConfirmButton: true
} as SweetAlertOptions;