“CheerioOptions”类型节点中不存在“normalizeWhitespace”

问题描述 投票:0回答:1

将 Node 模块 Cheerio 从 0.22.0 更新到 1.0.0-rc.12 后,出现以下错误

Object literal may only specify known properties, and 'normalizeWhitespace' does not exist in type 'CheerioOptions'.

normalizeWhitespace: true,

代码:

const $ = load(html, {
  decodeEntities: true,
  normalizeWhitespace: true,
});

如果我删除该选项,行为会发生变化,但我找不到应该使用哪个选项。

我有节点 v18

node.js typescript npm node-modules cheerio
1个回答
0
投票

尝试

CheerioParserOptions

import * as cheerio from 'cheerio';

const html = '<h2 class="title">Hello world</h2>';

const opts: cheerio.CheerioParserOptions  = {
  decodeEntities: true,
  normalizeWhitespace: true,
}

const $ = cheerio.load(html, opts);
© www.soinside.com 2019 - 2024. All rights reserved.