Webstorm无法识别…道具的道具类型>> [

问题描述 投票:0回答:1
我正在声明这样的函数:

const StudentVideoContainer = ({ course, video, currentScore, storedScore, goal, match, ...props}) => {

其中有一些我不想破坏的附加到props对象上的动作。海事组织,那条链足够长。但是,道具类型似乎不愿意识别这些功能,只要我不知道。enter image description here

我这样宣告了我的原型:

StudentVideoContainer.propTypes = { course: PropTypes.shape({ course: PropTypes.shape({}), sections: PropTypes.array, }), video: PropTypes.shape({}), currentScore: PropTypes.number, storedScore: PropTypes.number, goal: PropTypes.number, props: PropTypes.shape({ getStudentSingleCourse: PropTypes.func, clearStudentSingleCourse: PropTypes.func, getStudentVideo: PropTypes.func, clearStudentVideo: PropTypes.func, }), match: PropTypes.shape({ params: PropTypes.shape({ courseId: PropTypes.string, videoId: PropTypes.string, }) }) }; StudentVideoContainer.defaultProps = { course: PropTypes.shape({}), video: PropTypes.shape({}), currentScore: PropTypes.number, storedScore: PropTypes.number, goal: PropTypes.number, props: { getStudentSingleCourse: PropTypes.func, clearStudentSingleCourse: PropTypes.func, getStudentVideo: PropTypes.func, clearStudentVideo: PropTypes.func, }, match: PropTypes.shape({ params: PropTypes.shape({ courseId: PropTypes.string, videoId: PropTypes.string, }) }) };

[我尝试将我为match放置的所有内容都放在props定义内,并且webstorm不再承认它是有效的,但是当我将其拉回并对其进行结构分解时,webstorm认为它是有效的。在道具未通过验证的控制台中,我没有收到任何错误。而且,如果我将props下的任何函数更改为PropTypes.func之外的任何其他函数,则会收到一个错误,提示您期望该函数,因此我有理由确定它们实际上已通过验证。 

我做错什么了吗?

虽然从技术上讲这不会产生任何错误,但是红线会让我发疯,所以我不喜欢下一行抑制注释。直到大约2周前,我才知道像这样的道具验证还不是一件容易的事,所以我认为我做错了。

我正在声明这样的函数:const StudentVideoContainer =({课程,视频,currentScore,storedScore,目标,比赛,... props})=> {其中有几个动作附加到...] >

javascript reactjs react-proptypes
1个回答
1
投票
但是如果使用...props,将不会引入名为props的新属性,在这种情况下,这应该可以工作:

// Instead of this props: PropTypes.shape({ getStudentSingleCourse: PropTypes.func, clearStudentSingleCourse: PropTypes.func, getStudentVideo: PropTypes.func, clearStudentVideo: PropTypes.func, }), // Use this (same applies for the defaultProps) getStudentSingleCourse: PropTypes.func, clearStudentSingleCourse: PropTypes.func, getStudentVideo: PropTypes.func, clearStudentVideo: PropTypes.func,

© www.soinside.com 2019 - 2024. All rights reserved.