0

Using Vue 3, I'm getting the following error:

Type 'null' is not assignable to type 'number'.

This is the relevant code:

interface ComponentState {
  heroSelected: number;
}

export default defineComponent({
  name: 'Battle',
  setup() {
    const state: ComponentState = reactive({
      heroSelected: null,

I also tried undefined instead of null. I do not want to initialize my variable heroSelected to 0 or any other numerical value (in which case I don't get any error).

So what can I do to initialize it in a way that doesn't trigger an error?

drake035
  • 3,955
  • 41
  • 119
  • 229

1 Answers1

2

Your interface should be defined as follows :

interface ComponentState {
  heroSelected: number | null| undefined;
}
Boussadjra Brahim
  • 82,684
  • 19
  • 144
  • 164