小编Loo*_*Boi的帖子

类型'Readonly <{children?:ReactNode;不存在属性'XYZ'。}>和只读<{}>'

修正:我在全球范围内卸载了VScode,打字稿和eslint。一旦我重新安装了VScode,一切都会恢复正常。

更新:安装@ types / react库后,我仍然仅对RecipeList.js和Recipe.js都得到类似的错误,属性“ props”中提到的在 类型“ Home”上不存在TypeScript属性“ props”不存在

属性'recipes'在类型'Readonly <{children?:ReactNode;上不存在。}>和只读<{}>'。

![安装@ types / react库后出现类似错误

原文:所以我是React的新手,由于某种原因,在VSCode上,尝试访问RecipeList.js和Recipe.js的.props时遇到语法错误。

这是Recipe.js的代码示例:

import React, {Component} from 'react';
import "./Recipe.css";

class Recipe extends Component {

    // props: any; uncommenting this will fix the bug

    render() {
        // don't have to use return and parentheses for arrow with JSX
        const ingredients = this.props.ingredients.map((ing, ind) => (
            <li key={ind}>{ing}</li>
        ));
        const {title, img, instructions} = this.props

        return (
            <div className="recipe-card">
                <div className="recipe-card-img">
                    <img src={img} alt={title}/> …
Run Code Online (Sandbox Code Playgroud)

javascript babel typescript reactjs visual-studio-code

8
推荐指数
3
解决办法
7793
查看次数