Vee-validate: [v3] Export a ValidationObserver type

Created on 3 Sep 2019  路  4Comments  路  Source: logaretm/vee-validate

Is your feature request related to a problem? Please describe.
Maybe I'm doing something wrong, but I think we need a valid ValidationObserver type to be exported for situations like:

image

Otherwise you end up with the error Property 'validate' does not exist on type 'Vue | Element | Vue[] | Element[]'.

Describe the solution you'd like
Export a ValidationObserver type (not a value)

Describe alternatives you've considered
You can't use the value ValidationObserver that is currently exported from vee-validate because that causes the TypeScript error 'ValidationObserver' refers to a value, but is being used as a type here.

EDIT:
My current shim looks like:

    interface ValidationObserver extends Vue {
      validate: () => Promise<boolean>;
    }

Most helpful comment

You missed this note here

If you are using TypeScript you may face issues with $refs not giving you the correct typings, you can solve that by defining them as ValidationProvider instances:

export default class App extends Vue {
  $refs!: {
    provider: InstanceType<typeof ValidationProvider>;
  };
}
this.$refs.provider.setErrors(['some error']);

You can do the same with observers and you will get full typings for them.

All 4 comments

You missed this note here

If you are using TypeScript you may face issues with $refs not giving you the correct typings, you can solve that by defining them as ValidationProvider instances:

export default class App extends Vue {
  $refs!: {
    provider: InstanceType<typeof ValidationProvider>;
  };
}
this.$refs.provider.setErrors(['some error']);

You can do the same with observers and you will get full typings for them.

Thanks @logaretm, I feel stupid for missing that!

@jwhitmarsh Don't feel bad, we miss stuff all the time 馃榿

For those using vue-property-decorators this can be done in a similar manner:

@Component
export default class Balancing extends Vue {
  @Ref()
  readonly refName!: InstanceType<typeof ValidationObserver>
  ...
  doSomething() {
    this.refName.reset();
  }
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

triffer picture triffer  路  3Comments

Etheryte picture Etheryte  路  3Comments

YamenSharaf picture YamenSharaf  路  3Comments

7immer picture 7immer  路  3Comments

parweb picture parweb  路  3Comments