报错事例
typtscript 组件中定义方法报错
不能将类型“{ onRef: (ref: any) => void; }”分配给类型“IntrinsicAttributes & IntrinsicClassAttributes<Component<Omit<IProps, “form”>, any, any>> & Readonly<…> & Readonly<…>”。
类型“IntrinsicAttributes & IntrinsicClassAttributes<Component<Omit<IProps, “form”>, any, any>> & Readonly<…> & Readonly<…>”上不存在属性“onRef”。
父组件中:

解决方法
子组件中按照图片规范方法即可
onRef:(ref: any) => void;

结果
无标红报错


本文档描述了在TypeScript组件中遇到onRef属性不匹配导致的错误,详细解释了父组件传递方法时与子组件接收方法的类型不一致的问题。通过提供子组件正确定义onRef的方法(onRef:(ref:any) => void),成功消除了报错,实现了无标红的正确状态。解决方案对理解TypeScript组件间通信及类型匹配具有参考价值。
5万+

被折叠的 条评论
为什么被折叠?



