属性“图片”在类型“ IntrinsicAttributes和IntrinsicClassAttributes”上不存在

时间:2018-07-01 20:08:17

标签: typescript recompose

我正在尝试学习将Recompose与Typescript结合使用。代码的打击很正常,但是在代码编辑器中却给我一个错误。问题与将props传递到HOC有关。

interface IPicture {
    description: string;
    imageUrl: string;
}

interface IProps {
    pictures: IPicture[];
    index: number;
    prev: (len: number) => IEventListener;
    next: (len: number) => IEventListener;
}

interface IEventListener {
    handleEvent(evt: Event): void;
}

const PictureSlide: React.SFC<IProps> = ({ pictures, index, prev, next }) => {
    return (
        <Card>
            <img src={pictures[index].imageUrl} alt="picture" />
            <div
                style={{
                    display: "flex",
                    justifyContent: "space-between",
                    width: "100%",
                }}
            >
                <Button color="primary" onClick={() => prev(pictures.length)}>
                    Prev
                </Button>
                <Button color="primary" onClick={() => next(pictures.length)}>
                    Next
                </Button>
            </div>
        </Card>
    );
};

const enhancer = compose(
    withState("index", "updateIndex", 0),
    withHandlers({
        next: ({ updateIndex }) => (max: number) =>
            updateIndex((n: number) => (n === max ? 0 : n + 1)),
        prev: ({ updateIndex }) => (max: number) =>
            updateIndex((n: number) => (n === 0 ? max : n - 1)),
    })
);

export default enhancer(PictureSlide);

并从另一个组件导入该组件:

<PictureSlide pictures={coverCropSlideImages} />

文件符合要求,但是我在代码编辑器中收到一条错误消息:

  

[ts]属性'pictures'在类型'IntrinsicAttributes&IntrinsicClassAttributes>和Readonly <{c ...'上不存在。

0 个答案:

没有答案