无法调用类型缺少调用签名的表达式。类型“typeof import("sweetalert2")”没有兼容的调用签名

sre*_*vas 2 angular sweetalert2

我收到“无法调用类型缺少调用签名的表达式。类型 'typeof import("sweetalert2")' 没有兼容的调用签名。” 在角度中使用 SWAL 时出现此错误。

我的 package-cli.json 看起来像

    "ng2-sweetalert2": {
    "version": "0.0.8",
    "resolved": "https://registry.npmjs.org/ng2-sweetalert2/-/ng2-sweetalert2-0.0.8.tgz",
    "integrity": "sha1-+VkDV2dqeLIMf3eFTLVt/cJda0Q=",
    "requires": {
        "lodash.assign": "^4.0.8",
        "sweetalert2": "^5.2.0"
    },
    "dependencies": {
        "es6-promise": {
            "version": "4.2.6",
            "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.6.tgz",
            "integrity": "sha512-aRVgGdnmW2OiySVPUC9e6m+plolMAJKjZnQlCwNSuK5yQ0JN61DZSO1X1Ufd1foqWRAlig0rhduTCHe7sVtK5Q=="
        },
        "sweetalert2": {
            "version": "5.3.8",
            "resolved": "https://registry.npmjs.org/sweetalert2/-/sweetalert2-5.3.8.tgz",
            "integrity": "sha1-YALBhFPQYMQLnMVL+DoBDHHjlik=",
            "requires": {
                "es6-promise": "^4.2.6"
            }
        }
    }
}

"sweetalert2": {
      "version": "8.9.0",
      "resolved": "https://registry.npmjs.org/sweetalert2/-/sweetalert2-8.9.0.tgz",
      "integrity": "sha512-gI+wL44QRbfd6FvRVB8KKLQPhD/8jP3XUNrvYGcSlU7IA09dQtQw3rrLCbM3c+HY0L3O8VTz1Gvu29n8ryIgag=="
}
Run Code Online (Sandbox Code Playgroud)

我在 package.json 依赖项中有以下内容

"dependencies":{
"ng2-sweetalert2": "0.0.8",
"sweetalert2": "^8.9.0",}
Run Code Online (Sandbox Code Playgroud)

在组件中我的代码如下所示

import * as swal from 'sweetalert2';

        swal({
          text: 'Login Successful!',
          timer: 1000,
          onOpen: () => {
            swal.showLoading()
          }
        })then((result) => {
          if (result.dismiss === swal.DismissReason.timer) {
              // calling few required functions here
          }
        })
Run Code Online (Sandbox Code Playgroud)

在组件中我收到上述错误。查了很多资料还是没能找出问题所在。请帮我。

小智 5

我也有同样的问题。使用

swal.fire() 
Run Code Online (Sandbox Code Playgroud)

代替

swal()
Run Code Online (Sandbox Code Playgroud)

它会解决你的问题。