I have a component that looks like this:
export interface Props {
// ... some props
}
export interface State {
readonly mode: "add" | "delete"
}
export class MyComponent extends Component<Props, State> {
readonly state = { mode: "add" }
// ... more component code
}
The problem is this throws the linting error:
Property 'state' in type 'ScannerScreen' is not assignable to the same property in base type 'Component<Props, State, any>'.
Type '{ mode: string; }' is not assignable to type 'Readonly<State>'.
Types of property 'mode' are incompatible.
Type 'string' is not assignable to type '"add" | "delete"'.
Why does TypeScript not recognize that "add"
or "delete"
are strings or that "add"
is one of the allowed types for mode?