【发布时间】:2020-04-07 14:10:13
【问题描述】:
为什么 TypeScript 会警告 Property 'attr' does not exist on type 'CheerioElement'?
async function inlineImages(serializedSvg: string) {
const $ = cheerio.load(serializedSvg);
await Promise.all(
Array.from($('image[href^="http"]')).map(async (el: CheerioElement) => {
const url = el.attr("href"); // <--- HERE
if (!url) {
return;
}
const data = await requestBase64(url);
if (!data) {
return;
}
el.attr("href", data); // <--- AND HERE
})
);
return serializedSvg;
}
【问题讨论】:
标签: typescript cheerio