我正在使用带有select2
插件的Angular 4。我已经为@types
和jquery
添加了select2
。 Vscode intellisense显示为方法select2并且不会抛出任何错误,但angular-cli的编译失败。
我有类似的问题并通过导入修复它:
import 'select2';
我之前安装的:
npm install select2 --save
一旦你这样做,你可以像往常一样通过jQuery使用库,你的IDE不会抱怨它。
在我的情况下,那是因为我导入了另一个库(sweetalert2),错误的jQuery定义。
在sweetalert2.d.ts
第885行:
/**
* These interfaces aren't provided by SweetAlert2, but its definitions use them.
* They will be merged with 'true' definitions.
*/
// tslint:disable:no-empty-interface
interface JQuery {
}
这会覆盖错误结果的JQuery
定义(最初应该是JQuery<T = HTMLElement>
)。删除后一切正常运行。