Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vincent15000's avatar

Initial value of data set to null for Number format

Hello,

I have these data declared in my component. pathId need to be a Number, but when I load this component, pathId is null (it's normal).

So I get a warning saying that pathId should be a number. How is it possible to tell VueJS that pathId has to be a number or to be null ? So that I don't get any warning.

data() {
  return {
    pathId: Number,
    pathDialog: false,
  }
},

Thanks ;).

V

0 likes
3 replies
tykus's avatar
tykus
Best Answer
Level 104

I've never seen data type constraints specified like this before; only props. Is there some documentation to back this approach up?

1 like
vincent15000's avatar

@tykus No idea ... effectively I have set formats myself without checking if it's common to do that with datas.

tykus's avatar

@vincent15000 I don't know that this is possible - the purpose of data is to set state, not to define types. I have seen in Typescript examples, the empty state being set using the as keyword like this:

data() {
  return {
    items: [] as Item[] // Item is a type
  }
},

But is does not make sense in your context.

Please or to participate in this conversation.