Property 'value' does not exist on type 'Readonly<{}>'
The Component
is defined like so:
interface Component<P = {}, S = {}> extends ComponentLifecycle<P, S> { }
Meaning that the default type for the state (and props) is: {}
.
If you want your component to have value
in the state then you need to define it like this:
class App extends React.Component<{}, { value: string }> { ...}
Or:
type MyProps = { ... };type MyState = { value: string };class App extends React.Component<MyProps, MyState> { ...}
interface MyProps { ...}interface MyState { value: string}class App extends React.Component<MyProps, MyState> { ...}// Or with hooks, something likeconst App = ({}: MyProps) => { const [value, setValue] = useState<string>(''); ...};
type
's are fine too like in @nitzan-tomer's answer, as long as you're consistent.
If you don't want to pass interface state or props model you can try this
class App extends React.Component <any, any>