mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 23:07:06 +00:00
vuelidate: Add function call signature to ValidationRule (#39206)
* Add function definition to ValidationRule ValidationRule is a function that takes in parameters and then applies them to the inner validator function. The types are currently missing that allow this behavior. This is most useful when building composed functions out of the built-in validators, like so: ```typescript export const greaterThanZero: ValidationRule = and(minValue(0), not((value: UserInput) => value == 0)) export const greaterThanOrEqualToZero: ValidationRule = minValue(0) ``` Vuelidate "withParams" reference that returns a ValidationRule function: https://github.com/vuelidate/vuelidate/blob/bb23f01ab4f14a813a25cff8defb7788cd8859ac/src/params.js#L36-L55 * unknown -> any for TS < 3.0 * Fix unrelated noImplictAny for TypeScript@next
This commit is contained in:
committed by
Wesley Wigham
parent
aa11bb97dc
commit
e4da6e8797
Vendored
+1
@@ -14,6 +14,7 @@ export interface ValidationParams {
|
||||
|
||||
// const ValidationRule
|
||||
export interface ValidationRule {
|
||||
(...params: any[]): boolean
|
||||
$params(): ValidationParams
|
||||
$pending(): boolean
|
||||
}
|
||||
|
||||
@@ -19,9 +19,11 @@ const contains = (param: string): CustomRule =>
|
||||
|
||||
const mustBeCool3 = helpers.withParams(
|
||||
{ type: 'mustBeCool3' },
|
||||
(value) => !helpers.req(value) || value.indexOf('cool') >= 0
|
||||
(value: any) => !helpers.req(value) || value.indexOf('cool') >= 0
|
||||
)
|
||||
|
||||
const mustBeCool3Result: boolean = mustBeCool3(50)
|
||||
|
||||
const mustBeCool4 = helpers.regex('mustBeCool4', /^.*cool.*$/)
|
||||
|
||||
const mustBeSame = (reference: string) => helpers.withParams(
|
||||
|
||||
Reference in New Issue
Block a user