The TypeScript 'props' property does not exist

advertisements

I have this .tsx file

import React, { Component } from 'react';

export class SidebarItem extends Component {
    constructor (props) {
        super(props);
    }

    render () {
        return (<li>{this.props.children}</li>);
    }
}

However, TypeScript throws this error: error TS2339: Property 'props' does not exist on type 'SidebarItem'.


You can try the following way of writing a React Comp.

interface SidebarItemProps
{
    children: any
} 

class SidebarItem extends React.Component<SidebarItemProps, any> {
    //your class methods
}

More about using React in TypeScript