【发布时间】:2023-01-18 02:37:46
【问题描述】:
我确实收到此函数的打字稿错误'node' is possibly 'null':
import { MatcherFunction } from '@testing-library/react'
type Query = (f: MatcherFunction) => HTMLElement
export const withMarkup = (query: Query) => (text: string) => {
const hasText = (node: Element) => node.textContent === text
return query((_, node) => {
const childrenDontHaveText = Array.from(node.children).every(
(child) => !hasText(child)
)
return hasText(node) && childrenDontHaveText
})
}
我想得到一些解释如何处理这个问题
【问题讨论】:
标签: typescript