この関数をプロトタイプからタイプスクリプトのjqueryに移植しようとしています:
onFailure: function(xhr) {
// Get options
var opts = this;
// Show result
var msgBox = opts.msgBox ? opts.msgBox : opts.client.options.msgBox;
if (msgBox && !opts.onFailure) {
msgBox.showError('Communicatie fout.');
}
// Handle onFailure callback
if (opts.onFailure) {
opts.onFailure.bind(opts.client)(xhr);
}
else if (opts.options && opts.options.onFailure) {
opts.options.onFailure.bind(opts.client)(xhr);
}
// Fire event
opts.client.failureCb.fire('failure');
},
これは移植されたコードです:
onFailure(xhr){
// Get options
var opts = this;
// Show result
var msgBox = opts.msgBox ? opts.msgBox : opts.client.options.msgBox;
if (msgBox && !opts.onFailure) {
msgBox.showError('Communicatie fout.');
}
// Handle onFailure callback
if (opts.onFailure) {
opts.onFailure(opts.client)(xhr);
}
else if (opts.options && opts.options.onFailure) {
opts.options.onFailure.bind(opts.client)(xhr);
}
// Fire event
opts.client.failureCb.fire('failure');
}
ご覧のとおり、それほど違いはありません。ただし、問題は typescript コンパイラから発生します。
エラー TS2094: プロパティ 'bind' は型 'null' の値に存在しません
これをどのようにjqueryに正しく移植する必要がありますか?
ありがとう。