1

I've downloaded the following app (which works in the sandbox):

https://codesandbox.io/s/wbkd-react-flow-forked-78hxw4

Locally, after I run:

npm install

and then

npm start

I get the following error:

TypeScript error in /wbkd-react-flow-forked/src/components/ErrorBoundary.tsx(6,15):
Parameter 'props' implicitly has an 'any' type.  TS7006

    4 | 
    5 | export class ErrorBoundary extends Component {
  > 6 |   constructor(props) {
      |               ^
    7 |     super(props);
    8 |     this.state = { hasError: false };
    9 |   }

How do I resolve the compile error?

3
  • Please include the relavent code in the question, do not link to external resources Commented Aug 30, 2022 at 10:40
  • 1
    You don't seem to use strong-typed props, hence the error. react-typescript-cheatsheet.netlify.app/docs/basic/… Commented Aug 30, 2022 at 10:42
  • you don't use typescript in the project but file extension is tsx. Change it to ErrorBoundary.jsx Commented Aug 30, 2022 at 11:03

1 Answer 1

1

Add typing to your props:

type ErrorBoundaryProps = {
  someProps: boolean;
}

export class ErrorBoundary extends Component<ErrorBoundaryProps> {
  constructor(props) {
    super(props);
    this.state = { hasError: false };
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.