You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React自定义组件传props报IntrinsicAttributes相关TS错误如何解决?

问题原因与修复方案

类型报错根因

你定义FadeInSection组件时,没有给FunctionComponent传入对应的Props泛型参数,导致TypeScript无法识别该组件支持传入offset属性,因此触发类型报错。
原错误写法:

export const FadeInSection: FunctionComponent = ({ offset, children }: FadeInSectionProps) => {

修复写法:

// 将Props类型传入FunctionComponent泛型,参数自动继承类型无需重复注解
export const FadeInSection: FunctionComponent<FadeInSectionProps> = ({ offset, children }) => {

可选优化:避免自定义样式属性丢失

你使用的@styled-system/should-forward-prop默认仅转发HTML标准属性和styled-system内置属性,虽然当前功能运行正常,但为了避免后续迭代出现样式失效问题,建议将自定义的offset属性加入转发白名单:

const Section = styled.div.withConfig({
  shouldForwardProp: (prop) => prop === 'offset' || shouldForwardProp(prop),
})<{ offset?: number }>`
  // 原有样式逻辑保持不变
`;

Input相关报错处理

你贴出的报错信息属于Input组件的类型错误,和当前的FadeInSection组件无关联:
请检查你自行封装的Input组件的InputProps接口定义,补充type?: string字段即可消除该报错。

内容的提问来源于stack exchange,提问作者Toni Michel Caubet

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 00:09:02