Categories
TypeScript Answers

How to fix the “Property ‘value’ does not exist on type ‘Readonly<{}>‘ ” error with React TypeScript?

Spread the love

To fix the "Property ‘value’ does not exist on type ‘Readonly<{}>’ " error with React TypeScript, we should specify the prop and state types in our React class component.

For instance, we write

type MyProps = {
  //...
};
type MyState = { value: string };
class App extends React.Component<MyProps, MyState> {
  //...
}

to specify the MyProps and MyState types as the types for the props and state of our React class component with

React.Component<MyProps, MyState>

We should add value into the type specification since it’s specified in the error.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *