Answer the question
In order to leave comments, you need to log in
How to specify type in vue Router?
Hello, I'm using typescript in a project and I need to compare a static value of type number with the
id == this.$route.query.id
//id passed through the router exactly number and this.$route.query.id should also be considered a number, but for some reason it's not...
But typescript
This condition will always return 'false' since the types 'number' and 'LocationQueryValue | LocationQueryValue[]' have no overlap.
Answer the question
In order to leave comments, you need to log in
LocationQueryValue is a type alias for string | null. You must check that the identifier from the query parameters is not null, in which case cast it to a number using the String constructor.
String('1') === 1 // true
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question