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>Tengo un problema con un código. Recibí un error de tipo para la propiedad de nombre de usuario. Intento cambiar el tipo de cadena a un tipo cualquiera, pero eso no resolvió mi problema. ¿Alguna sugerencia?
ERROR:
Escriba '{ abierto: booleano; producto: IProducto | nulo; handleClose: () => vacío; nombre de usuario: cadena; }' no se puede asignar al tipo 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly & Readonly<...>'. La propiedad 'nombre de usuario' no existe en el tipo 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly & Readonly<...>'.ts(2322)
Por el mensaje de error, parece que el componente DetailView no admite un accesorio de nombre de username . Es decir, el error que ves con el siguiente código:
<DetailView open={this.state.showDetails} product={this.state.product} handleClose={this.handleClose} username={this.state.username}></DetailView> no se debe a que el nombre de username esté ausente en el estado, sino a que el componente DetailView espera accesorios diferentes.