programing

Reactjs, Typescript - 속성이 하위 구성 요소에 없습니다.

minimums 2023. 6. 12. 21:15
반응형

Reactjs, Typescript - 속성이 하위 구성 요소에 없습니다.

나는 리액트와 함께 2.3.4 타입 스크립트 2.3.4를 사용하고 있습니다.오류 TS2339: 오류 TS2339: 속성 'name'이(가) 유형 'Readonly<{children?'에 없습니다.:ReactNode; }> & 읽기 전용 <{}>.하위 구성 요소에서 속성을 선언하려고 하면 오류가 발생합니다.하위 구성 요소에서 속성을 올바르게 참조하려면 어떻게 해야 합니까?

어떤 이유로 인해 코드가 스크립트 실행자에서 실행되지 않습니다.

어떤 도움이든 감사합니다.

export interface person {
    name: string;
    age: number;
}

interface State {
    personArray: person[];
}

interface Props {

}


class ProfileData extends React.Component<{}, person> {
    public render() {
        return (
            <section>
                <section>
                    <h3>profile 1</h3>
                    <div>{this.props.name}</div>
                </section>
            </section>
        )

    }
}

export class Profile extends React.Component<Props, State> {
    public state: State;
    public props: Props;
    constructor(props: Props){
        super(props);
            this.state = {
                personArray: [
                    {
                        name: 'bazaaa', 
                        age: 42
                    },
                    {
                        name: 'louis', 
                        age: 24
                    }
                ]
            };
    }

    public render() {
        let profile1 = this.state.personArray[0];
        return (
            <ProfileData 
            name={profile1.name}
            />
        )
    }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>

신고하는 것을 잊으셨습니다.name의 React 속성으로ProfileData클래스 정의.다음과 같은 방법이 사용될 것입니다.

class ProfileData extends React.Component<{name: string}, person> {

언급URL : https://stackoverflow.com/questions/44489338/reactjs-typescript-property-does-not-exist-on-child-component

반응형