类型错误:类型“ {}”中缺少属性“ Store”,但类型为“ Readonly <istore>”时必需。 TS2741

时间:2019-02-07 18:46:03

标签: reactjs typescript mobx

您好,请您帮我解决这个问题。

我想做的就是将商店作为道具传递给组件,但出现此错误

Type error: Property 'Store' is missing in type '{}' but required in type 'Readonly<Istore>'.  TS2741

    import React, { Component } from 'react';
import logo from './logo.svg';
import { observable, computed } from 'mobx'
import { observer } from 'mobx-react'
import TodoListView from "./TodoListView";
import 'bootstrap/dist/css/bootstrap.min.css'
import NotesAdd from './NotesAdd';
import NotesView from './NotesView';
import DevTools from 'mobx-react-devtools'
import Loader from './Loader';
import { Store } from "../store/Store"
import makeInspectable from 'mobx-devtools-mst';
import Wall from './Wall';
import { inject } from 'mobx-react';
import NotesStore from "../store/NotesStore";
import CounterStore from "../store/CounterStore";


interface IStoreStores {
    NotesStore: NotesStore,
    CounterStore: CounterStore,
}

interface Istore {
    Store: IStoreStores
}


@inject("Store")
@observer
class Box extends Component<Istore> {
    render() {
        console.log('props', this.props)
        return (
            <div className="Box p-3" >
                box component {this.props.Store.CounterStore.counter}
        <Wall />
            </div>
        );
    }
}

export default Box;

1 个答案:

答案 0 :(得分:0)

商店道具在此必不可少:

interface Istore {
    Store: IStoreStores
}

将其更改为可选:

interface Istore {
    Store?: IStoreStores
}