这是一个错误,每次我们在 jQuery 循环中初始化 $(this)
时,我们似乎都会在 PhpStorm 中遇到这个错误。经过数小时/数天的研究,我未能找到有关 PhpStorm 为何将其标记为错误的任何信息。
我们使用 typescript-eslint-parser
进行 linting,它不会标记任何错误。
这只是 PhpStorm 的问题,还是真正的 TypeScript 错误?
能否解决或忽略?
这些是安装的类型:
"@types/axios": "^0.14.0",
"@types/bootstrap": "3.3.36",
"@types/node": "8.5.1",
"@types/jquery": "3.2.7",
"@types/qs": "^6.5.1",
$.fn.extend({
performanceCharts: function (): JQuery {
'use strict'
$(this).each(function (): void {
let $this: JQuery = $(this)
});
}
})
$(document).ready(function () {
$('.js-performance-charts').performanceCharts()
})
<div class="js-performance-charts"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
最佳答案
已解决:应该是PhpStorm的版本问题。从2017.1升级到2017.3后问题消失。
关于jquery - 初始化器类型 JQuery<TElement> 不可分配给变量类型 JQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47892424/