我有一个Angular TypeScript文件里的代码:
$('.dashboard-table').on('click', 'tbody tr',
function(event: JQueryEventObject) { // changing this to any removes TS error
const test: Test = <Test>$('.dashboard-table').DataTable().row(this).data();
self.openTest(test.id, event);
}
);
openTest(id: number, $event: MouseEvent|JQueryEventObject) {
let target = $event.srcElement || $event.target as HTMLElement;
if (target.tagName.toLowerCase() == 'a'
|| $(target).parents('a').length
|| target.tagName.toLowerCase() == 'button'
|| $(target).parents('button').length) {
return;
}
this.router.navigate([this.urls.paths.test(id)]);
}
它抛出了一个TypeScript错误:
error TS2345: Argument of type '"click"' is not assignable to parameter of type
'PlainObject<false | EventHandler<HTMLElement,
(this: HTMLElement, event: JQueryEventObject) => vo...'.`.
我如何让ng serve
不截断TypeScript错误消息? 如何重写它以避免失败的TypeScript检查?