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?

0

1 Answer 1

2

Your interface should be defined as follows :

interface ComponentState {
  heroSelected: number | null| undefined;
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.