Javascript 这应该是什么类型的错误?

Javascript 这应该是什么类型的错误?,javascript,reactjs,error-handling,Javascript,Reactjs,Error Handling,以这段代码为例: class Wizard extends Component { constructor(props) { super(props); this.state = { steps: this.props.children ? this.props.children.length : null } } componentWillMount() { if (this.s

以这段代码为例:

class Wizard extends Component {
    constructor(props) {
        super(props);

        this.state = {
            steps: this.props.children ? this.props.children.length : null
        }
    }

    componentWillMount() {
        if (this.state.steps === null) {
            throw new Error(
                "The <Wizard /> component requires <Step /> components as children"
            );
        }
    }
}
类向导扩展组件{
建造师(道具){
超级(道具);
此.state={
步骤:this.props.children?this.props.children.length:null
}
}
组件willmount(){
if(this.state.steps==null){
抛出新错误(
“该组件需要将组件作为子组件”
);
}
}
}

这应该是什么类型的错误?我觉得应该有一个requirementer,但我从来没有听说过。

所以我认为这是一个PropType错误,由React的PropTypes模块处理。以下是指向文档页面的链接:

PropTypes将对组件的Prop(恰当命名)运行类型检查,并根据它们是否缺少必需的键抛出信息/错误消息

代码示例:

import PropTypes from 'prop-types';

class MyComponent extends React.Component {
  render() {
    // This must be an array of children or it will warn.
    const children = this.props.children;
    return (
      <div>
        {children}
      </div>
    );
  }
}

MyComponent.propTypes = {
  children: PropTypes.arrayOf(PropTypes.element).isRequired
};
从“道具类型”导入道具类型;
类MyComponent扩展了React.Component{
render(){
//这必须是一个子数组,否则将发出警告。
const children=this.props.children;
返回(
{儿童}
);
}
}
MyComponent.propTypes={
子级:PropTypes.arrayOf(PropTypes.element).isRequired
};

编辑:根据React的上下文,我认为错误的类型应该是儿童类型错误

我引用了你对我问题的编辑。我真的很感兴趣的库/框架不可知的答案。框架不可知,我会认为这是一个儿童类型的错误,只是觉得最合适,因为儿童只是一个数组的子对象,ChildrenType是3个字符更长:(.我编辑了我的答案以反映这一点。好吧,这将是一个自定义错误类型。我不想成为一个痛苦的人,但我正在寻找更高层次的答案。我认为我在我的示例中过于具体,这是我的错。实际上我会接受你的答案,因为我没有正确地问我的问题,而你提供了一个很好的答案。