简体   繁体   English

类型上不存在属性“用户名”

[英]Property 'username' does not exist on type

 export let microEventBus: MicroEventBus = (window as any).microEventBus; export interface IAppState { showDetails: boolean; product: IProduct | null; collectionInstance: Collection; username: string; } //const collectionInstance = new Collection(); class App extends React.Component<IAppProps, IAppState> { constructor(props: IAppProps) { super(props); this.showDetailView = this.showDetailView.bind(this); this.handleClose = this.handleClose.bind(this); this.state = { showDetails: false, product: null, collectionInstance: new Collection(), username: '', }; } componentDidMount() { this.processUserLoginEvent = this.processUserLoginEvent.bind(this); microEventBus.on('user-logged-in').subscribe(this.processUserLoginEvent); ajax.getJSON('http://128.0.0.1:3000/products').subscribe((data) => { let collection = new Collection(); collection.items = data as IProduct[]; this.setState({ showDetails: false, product: null, collectionInstance: collection, }); }); } render() { return ( <div> {this.state.collectionInstance.items.length < 1? ( <div className='App-header'> <CircularProgress /> </div> ): ( '' )} <CollectionView {...this.state.collectionInstance} handlerItemClicked={this.showDetailView}></CollectionView> <DetailView open={this.state.showDetails} product={this.state.product} handleClose={this.handleClose} **problem**-->username={this.state.username}></DetailView>

I have problem with a code.我的代码有问题。 I got a type error for username property.我收到用户名属性的类型错误。 I try to change type of string to a type of any but that did't solved my problem.我尝试将字符串类型更改为任意类型,但这并没有解决我的问题。 Any sugestions?有什么建议吗?

ERROR:错误:

Type '{ open: boolean;输入'{打开:boolean; product: IProduct |产品: IProduct | null; null; handleClose: () => void; handleClose: () => void; username: string;用户名:字符串; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly & Readonly<...>'. }' 不可分配给类型 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly & Readonly<...>'。 Property 'username' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly & Readonly<...>'.ts(2322)类型“IntrinsicAttributes & IntrinsicClassAttributes & Readonly & Readonly<...>”上不存在属性“用户名”.ts(2322)

From the error message, it seems that the DetailView component does not support a username prop.从错误消息来看, DetailView组件似乎不支持username prop。 That is to say, the error you see with the following code:也就是说,您使用以下代码看到的错误:

      <DetailView
          open={this.state.showDetails}
          product={this.state.product}
          handleClose={this.handleClose}
          username={this.state.username}></DetailView>

is not because username is absent on state, but because the DetailView component expects different props.不是因为 state 上没有username ,而是因为DetailView组件需要不同的道具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM