diff --git a/types/vuelidate/index.d.ts b/types/vuelidate/index.d.ts index 216f07bb0f..bd981cac73 100644 --- a/types/vuelidate/index.d.ts +++ b/types/vuelidate/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for vuelidate 0.7 // Project: https://github.com/janesser/vuelidate.ts // Definitions by: Jan Esser +// Jubair Saidi // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.4 diff --git a/types/vuelidate/lib/validators.d.ts b/types/vuelidate/lib/validators.d.ts index 8f74f93687..04690c7ab6 100644 --- a/types/vuelidate/lib/validators.d.ts +++ b/types/vuelidate/lib/validators.d.ts @@ -18,10 +18,10 @@ export interface ValidationRule { $pending(): boolean } -export type CustomRule = (value: any, parentVm?: Vue) => boolean +export type CustomRule = (value: any, parentVm?: any) => boolean export interface Helpers { - withParams(params: Params, rule: CustomRule): ValidationRule + withParams(params: Params, rule: CustomRule | ValidationRule): ValidationRule req(value: any): ValidationRule ref(reference: string | ((vm: any, parentVm?: Vue) => any), vm: any, parentVm?: Vue): any len(value: any): number @@ -42,10 +42,13 @@ export function between(min: number, max: number): ValidationRule export function alpha(): ValidationRule export function alphaNum(): ValidationRule export function numeric(): ValidationRule +export function integer(): ValidationRule +export function decimal(): ValidationRule export function email(): ValidationRule export function ipAddress(): ValidationRule export function macAddress(): ValidationRule export function sameAs(field: string | ((vm: any, parentVm?: Vue) => any)): ValidationRule export function url(): ValidationRule -export function or(...validators: ValidationRule[]): ValidationRule -export function and(...validators: ValidationRule[]): ValidationRule +export function not(validator: ValidationRule | CustomRule): ValidationRule +export function or(...validators: Array): ValidationRule +export function and(...validators: Array): ValidationRule diff --git a/types/vuelidate/vuelidate-tests.ts b/types/vuelidate/vuelidate-tests.ts index 5385a935c2..0376c01cc1 100644 --- a/types/vuelidate/vuelidate-tests.ts +++ b/types/vuelidate/vuelidate-tests.ts @@ -1,5 +1,5 @@ import { Validation } from 'vuelidate' -import { required, minLength, sameAs, helpers } from 'vuelidate/lib/validators' +import { required, integer, decimal, minLength, sameAs, helpers } from 'vuelidate/lib/validators' import Vue, { ComponentOptions } from 'vue' @@ -54,14 +54,25 @@ const mustHaveLength = (minLen: number) => helpers.withParams( }, nestedB: { required + }, + nestedOfLength: { + mustHaveLength: mustHaveLength(6) } }, + age: { + required, + integer + }, + coolFactor: { + required, + decimal + }, flatA: { required }, flatB: { required }, forGroup: { nested: { required } }, - validationGroup: ['flatA', 'flatB', 'forGroup.nested'], + validationGroup: ['age', 'coolFactor', 'flatA', 'flatB', 'forGroup.nested'], people: { required, minLength: minLength(3), @@ -90,7 +101,7 @@ const mustHaveLength = (minLen: number) => helpers.withParams( required, mustBeCool, mustBeCool2, - containsA: contains("a"), + containsA: contains('a'), mustBeCool3 } } @@ -101,9 +112,13 @@ export class ValidComponent extends Vue { form = { nestedA: 'A', - nestedB: 'B' + nestedB: 'B', + nestedOfLength: '' } + age = 50 + coolFactor = 0.25 + flatA = '' flatB = '' forGroup = { @@ -132,6 +147,8 @@ export class ValidComponent extends Vue { console.log(this.$v.form.$params) console.log(this.$v.form.$params.nestedA) console.log(this.$v.form.nestedA) + console.log(this.$v.form.$params.nestedOfLength) + console.log(this.$v.form.nestedOfLength) } console.log(this.$v.validationGroup.$params) }