Using this keyword in Prop validator
See original GitHub issueI’m unable to use the this
keyword inside a @Prop
validator. Here is an example of what I’m trying to do:
@Prop({
default: 0,
type: Number,
validator: (x) => x >= this.minValue && x <= this.maxValue,
})
public value: number;
@Prop({
default: 100,
type: Number,
})
public maxValue: number;
@Prop({
default: 0,
type: Number,
})
public minValue: number;
The error I get from TypeScript is:
‘this’ implicitly has type ‘any’ because it does not have a type annotation.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
How to access the "this" component within the prop validator
I have several components, most of them have props, I execute validations on these props and some modifications if the object or array...
Read more >how to access "this" in props validator
the problem with that is that every time I write a validator, I'll have to import the {containsValue} from 'array.helpers.js' ? – Yung...
Read more >Using VueTypes Validators - GitHub Pages
Validates that a prop is an object with values of a certain type. Accepts JavaScript constructors, Vue.js props validation objects and VueTypes ...
Read more >How to Use Props in Vue.js
“Props” is a special keyword which stands for properties. It can be registered on a component to pass data from a parent component...
Read more >Validation | Amplience Developer Portal
The values authors can enter for a specific property can be constrained using validation keywords. These validation keywords can be used individually or ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi.
I apologize to you for late reply. I found that in
validator
functions,this
is not instance ofVue
.I think this is a bug,
this
should resolve to the current instance of the component. It just needs to be bound correctly.