Reactjs React typescript,属性';道具类型';不存在于类型';ToDofFilterItem';的类型;。TS2339
我有一个接口Reactjs React typescript,属性';道具类型';不存在于类型';ToDofFilterItem';的类型;。TS2339,reactjs,typescript,react-proptypes,Reactjs,Typescript,React Proptypes,我有一个接口 interface ITodoFilterItem { name: string, filter: string, filterTodos: any } 和引用它的同一文件中的类 class TodoFilterItem extends Component<ITodoFilterItem> { constructor (props:ITodoFilterItem) { super(props); this.handleFilter =
interface ITodoFilterItem {
name: string,
filter: string,
filterTodos: any
}
和引用它的同一文件中的类
class TodoFilterItem extends Component<ITodoFilterItem> {
constructor (props:ITodoFilterItem) {
super(props);
this.handleFilter = this.handleFilter.bind(this);
}
我得到:
仅供参考:我已经
从“道具类型”导入道具类型顶部的code>要求在类定义中初始化所有静态属性。将以下内容添加到类中,以确保TS可以正确分析该类
static propTypes: {
name: Requireable<string>;
filter: Requireable<string>;
filterTodos: Requireable<any>;
};
静态类型:{
名称:Requireable;
过滤器:需要;
filterTodos:必需的;
};
import React,{Component,Requireable}来自'React';
从“道具类型”导入道具类型;
接口ITodoFilterItem{
名称:字符串;
过滤器:字符串;
过滤气味:任何;
}
类ToDofFilterItem扩展组件{
静态支撑类型:{
名称:Requireable;
过滤器:需要;
filterTodos:必需的;
};
构造函数(道具:ITodoFilterItem){
超级(道具);
this.handleFilter=this.handleFilter.bind(this);
}
handleFilter(){}
render(){
回来
}
}
ToDofFilterItem.propTypes={
名称:PropTypes.string,
过滤器:PropTypes.string,
filterTodos:PropTypes.any,
};
导出默认TodoFilterItem;
TS要求在类定义中初始化所有静态属性。将以下内容添加到类中,以确保TS可以正确分析该类
static propTypes: {
name: Requireable<string>;
filter: Requireable<string>;
filterTodos: Requireable<any>;
};
静态类型:{
名称:Requireable;
过滤器:需要;
filterTodos:必需的;
};
import React,{Component,Requireable}来自'React';
从“道具类型”导入道具类型;
接口ITodoFilterItem{
名称:字符串;
过滤器:字符串;
过滤气味:任何;
}
类ToDofFilterItem扩展组件{
静态支撑类型:{
名称:Requireable;
过滤器:需要;
filterTodos:必需的;
};
构造函数(道具:ITodoFilterItem){
超级(道具);
this.handleFilter=this.handleFilter.bind(this);
}
handleFilter(){}
render(){
回来
}
}
ToDofFilterItem.propTypes={
名称:PropTypes.string,
过滤器:PropTypes.string,
filterTodos:PropTypes.any,
};
导出默认TodoFilterItem;
您是否需要道具类型
,因为您已经通过组件
定义了道具?除了编译时和运行时,我通常只使用其中一种。是的,我想在这种情况下同时使用这两种。这是否回答了您的问题?您是否需要propTypes
,因为您已经通过Component
定义了道具?除了编译时和运行时,我通常只使用其中一种。是的,我想在这种情况下同时使用这两种。这是否回答了您的问题?
static propTypes: {
name: Requireable<string>;
filter: Requireable<string>;
filterTodos: Requireable<any>;
};