Javascript – React Typescript property does not exist on type / IntrinsicAttributes & IntrinsicClassAttributes

javascriptreactjstypescript

New to TypeScript and this feels like it should be really simple but I can't quite get the syntax happy!

Very simple component:

import * as React from "react";
import ControlArea from "./ControlArea";

interface IControlAreaProps {
  welcome?: any;
}

export class Layout extends React.Component<IControlAreaProps> {
  public render() {
    return (
        <ControlArea welcome="This is the control area"/>
    );
  }
}

I'm getting the TS error Property 'welcome' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<ControlArea> & Readonly<{ children?: ReactNode; }>...'.

Any point in the right direction would be very much appreciated.

Best Answer

Your mistake here is that you're adding the interface to the Layout component when you should be adding them to the ControlArea component

interface IControlAreaProps {
  welcome?: any
}

export default class ControlArea extends React.Component<IControlAreaProps> {
  // Your ControlArea code
}
Related Topic