[英]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) => { });
}
我收到這些錯誤:
'類型參數'{標題:字符串; 文本:字符串; 類型:字符串; 顯示取消按鈕:布爾值; showConfirmButton: boolea...' 不能分配給類型為 'Settings & PromtModalSettings' 的參數。
輸入 '{ 標題:字符串; 文本:字符串; 類型:字符串; 顯示取消按鈕:布爾值; showConfirmButton: boolea...' 不可分配到類型 'PromtModalSettings'。 屬性“類型”的類型不兼容。 類型 'string' 不能分配給類型 'PromtType'。 在:'101,14' 來源:'ts'
錯誤錯誤:SweetAlert:意外的第二個參數(函數(刪除){...
我嘗試將options
類型設置為SweetAlert.Settings & SweetAlert.AlertModalSettings
,但我無法訪問命名空間SweerAlert
,並且還嘗試了any
. 他們都沒有工作。
如何將這些選項設置為 sweetalert?
Sweetalert 不需要安裝類型。 它已經實施了。 安裝類型時,我在原始類型之間發生沖突,然后出現錯誤。 我剛剛刪除了@types/sweetalert
,一切都像他們網站上的例子一樣。
一個簡單的修復是:
直接進入項目文件夾然后 \\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;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.