![](/img/trans.png)
[英]TypeScript error: Property 'children' does not exist on type '{ children?: ReactNode; }'
[英]Typescript - how do I fix "Property children does not exist" error on the children prop of a non-Typescript React component?
我有一個用tsx
擴展編寫的父組件和一個用“jsx”擴展編寫的子組件:
Child.jsx (不是實際的組件,只是一個示例)
const Child = props => {
const { children } = props
return (<a>{children}</a>)
}
父.tsx
const Parent = (props: IProps) => {
return (
<Child>This is my data</Child>
)
}
但是,我在 Parent.tsx 上收到Parent.tsx
錯誤:
類型“IntrinsicAttributes”上不存在屬性“子項”
現在,在一個完美的世界中,我可能會將Child.jsx
重構為 Typescript 文件並將children
屬性鍵入為React.ReactNode
但如果這是一個非常復雜且本身具有需要重構的子文件的遺留子文件怎么辦, ETC。?
有什么辦法可以克服 Parent 發出的 Typescript 錯誤?
React 18 停止包含隱式 children 道具。 您需要明確添加它。
https://solverfox.dev/writing/no-implicit-children/
我們需要開始向各種依賴項目提交 PR(到目前為止我已經做了兩次)以添加顯式的 children 屬性。 也許降級 React 版本直到這種情況平靜下來?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.