When I run my code, I encounter an error that says
Property 'attribs' does not exist on type 'Element'
. It's puzzling to me why this error is being thrown. After examining the type definitions of cheerio, I discovered that attribs
belongs to TagElement
. The issue seems to arise from the fact that the type Element
is automatically assigned to element
, and I'm unsure of how to rectify this. Considering I am new to typescript, it's likely that I've made a beginner mistake.
const $ = cheerio.load(response.body),
selection = $('td:nth-child(1) .spaceit_pad'),
filteredNodes = [];
selection.toArray().map((element) => {
const attr = element.attribs;
if (attr.class.split(' ').length === 1) {
filteredNodes.push(element);
console.log(typeof element);
}
});