【发布时间】:2019-05-03 09:22:22
【问题描述】:
我在 Typescript 项目中使用 Cheerio 来抓取 HTML 页面。但我不明白如何解决这个问题:
TS2683: 'this' implicitly has type 'any' because it does not have a type annotation.
这是我的代码。有什么想法吗?
import * as cheerioReq from 'cheerio-req';
async function crawl (options) {
await cheerioReq({ url: options.url, headers: options.headers }, (err, $: CheerioStatic) => {
if(err) console.log(err);
$('.title').each((i, elem) => {
console.log(i, elem, $(this).text().trim());
})
})
}
crawl(options);
【问题讨论】:
-
问题是您希望
this是谁?如果this应该由cheerioReq传递,请尝试使用常规函数而不是箭头函数
标签: typescript cheerio