Encountering an issue with Vue 3 where the error message reads:
Type 'null' is not assignable to type 'number'.
The problematic code snippet looks like this:
interface ComponentState {
heroSelected: number;
}
export default defineComponent({
name: 'Battle',
setup() {
const state: ComponentState = reactive({
heroSelected: null,
Attempting to use undefined
instead of null
did not resolve the issue. Reluctant to initialize heroSelected
as a numerical value like 0 to avoid errors.
How can I properly initialize it without triggering the error?