question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using this keyword in Prop validator

See original GitHub issue

I’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:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kaorun343commented, May 24, 2018

Hi.

I apologize to you for late reply. I found that in validator functions, this is not instance of Vue.

0reactions
RehanSaeedcommented, Jan 22, 2018

I think this is a bug, this should resolve to the current instance of the component. It just needs to be bound correctly.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found