TypeScript3.2.4を使用してAngular7にアップグレードし、コンパイルするたびに次のようになりました。
import swal from 'sweetalert';
swal({ ... });
node_modules / sweetalert / types / sweetalert.d.ts(4,9)のエラー:エラーTS2403:後続の変数宣言は同じ型である必要があります。 変数「swal」は「typeofimport( "C:/ Projects / me / browser / node_modules / sweetalert / types / sweetalert")」タイプである必要がありますが、ここでは「SweetAlert」タイプです。
node_modules/sweetalert/typings/sweetalert.d.ts
を編集した場合...
import swal, { SweetAlert } from "./core";
declare global {
const swal: SweetAlert;
const sweetAlert: SweetAlert;
}
export default swal;
export as namespace swal;
... に ...
import swal, { SweetAlert } from "./core";
export default swal;
export as namespace swal;
...動作を開始します。
何か案は?
同じ問題、同じ状況。
ただし、 export as namespace swal;
行をコメントアウトするだけでも、コンパイルできることに気付きました。 私は手がかりがないかTypeScriptの変更ログを見てきました...
同じ問題、同じ状況。
ただし、
export as namespace swal;
行をコメントアウトするだけでも、コンパイルできることに気付きました。 私は手がかりがないかTypeScriptの変更ログを見てきました...
同じ問題
私はこのソリューションを使用しました
しかし、私はこの解決策が正しいとは思いません。
同じ問題。
また、同じ問題。 このため、CIビルドは失敗します。
OpenBSDで実行しているときにも同じ問題が発生します。 はい、私は主流のOSを知りませんが、利用可能なTypeScriptのバージョンにより、sweetalertを使用できるものはすべて使用できなくなります:(
OpenBSDで実行しているときにも同じ問題が発生します。 はい、私は主流のOSを知りませんが、利用可能なTypeScriptのバージョンにより、sweetalertを使用できるものはすべて使用できなくなります:(
@ t4t5この問題を見ていただけますか?
Angular7でもこれを経験しています
定義ファイルを手動で編集する以外の回避策について何かアイデアはありますか? クローン/ npmをインストールするたびにそれを行うことを覚えているのは少し面倒になりつつあります。
@ bogdan-calapod CIビルドが失敗しないように、回避策としてこれを行っています。
sweetalert.min.js
として保存])。src/assets/scripts
にsweetalert.min.js
します。src/assets/scripts/sweetalert.min.js
にscripts
中のエントリangular.json
declare var swal: any;
追加します。swal
、つまりreturn swal({...})
を使用して、ファイル内のどこでもSweetalertを使用できます。npm uninstall sweetalert --save
こんにちは、みんな、
労力を節約し、sweetalert2を使用してくださいhttps://sweetalert2.github.io/
この問題に関する更新はありますか?
こんにちは、みんな、
労力を節約し、sweetalert2を使用してくださいhttps://sweetalert2.github.io/
これは3つ以上のボタンをサポートしていますか?
@DVGalarzaこの回避策は私にはうまく
@ alvarofelipe12'swal 'を使用しようとしているファイルで、ファイルの先頭(インポートの下)にdeclare var swal: any;
を追加しましたか? その場合は、 angular.json
の「スクリプト」セクションでsweetalert.min.js
が正しく参照されていることも確認してください。
TypeScript3.2.4を使用してAngular7にアップグレードし、コンパイルするたびに次のようになりました。
import swal from 'sweetalert'; swal({ ... });
node_modules / sweetalert / types / sweetalert.d.ts(4,9)のエラー:エラーTS2403:後続の変数宣言は同じ型である必要があります。 変数「swal」は「typeofimport( "C:/ Projects / me / browser / node_modules / sweetalert / types / sweetalert")」タイプである必要がありますが、ここでは「SweetAlert」タイプです。
node_modules/sweetalert/typings/sweetalert.d.ts
を編集した場合...import swal, { SweetAlert } from "./core"; declare global { const swal: SweetAlert; const sweetAlert: SweetAlert; } export default swal; export as namespace swal;
... に ...
import swal, { SweetAlert } from "./core"; export default swal; export as namespace swal;
...動作を開始します。
何か案は?
私の代替案は、constswalの名前をconst_swalに変更することでした
import swal、{SweetAlert} from "./core";
グローバルを宣言する{
const _swal:SweetAlert;
const sweetAlert:SweetAlert;
}
デフォルトのスワルをエクスポートします。
名前空間swalとしてエクスポートします。
こんにちは!、同じ問題
sweetalertタイプをオーバーライドすることでこれを修正しました。 src/node_modules/sweetalert/index.d.ts
という名前のファイルをsrcディレクトリに追加しました
//this file is needed because the sweetalert typings need to be overwritten because they are broken
//the real fix here is to stop using sweetalert
declare global {
const _swal: any;
const sweetAlert: any;
}
export default _swal;
export as namespace swal;
この行を変更して解決しました:
import swal from 'sweetalert';
に:
const swal = require('sweetalert');
または(インターフェース付き):
import { SweetAlert } from 'sweetalert/typings/core';
const swal: SweetAlert = require('sweetalert');
Angular 10でも同じ問題が発生しています。ええ、問題は私のIDEによるとsweetalert.d.ts
にあるようです。エラーがあるので、コメントするのは悪い解決策ではないと思います。
@drmencosそれはNode.js用ですか? require
はAngular10では機能しません。
ファイル内:node_modules> sweetalert> types> sweetalert.d.ts
コメント:const swal:SweetAlert;
インポートスワル、{SweetAlert} from "./core";
グローバルを宣言する{
// const swal:SweetAlert;
const sweetAlert:SweetAlert;
}
デフォルトのスワルをエクスポートします。
名前空間swalとしてエクスポートします。
import 'sweetalert'
をrequire('sweetalert')
うまくいきました。
最も参考になるコメント
こんにちは、みんな、
労力を節約し、sweetalert2を使用してくださいhttps://sweetalert2.github.io/