次のようなコンポーネントがあります。
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
}
問題は、これがリンティングエラーをスローすることです:
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"'.
TypeScriptが文字列である、または"add"
モードで許可されている型の 1 つであると認識しないのはなぜですか?"delete"
"add"