From 8f696141dcefac9145398e4a8d7ee230c39d37d4 Mon Sep 17 00:00:00 2001 From: Victor Garcia Date: Mon, 12 Jul 2021 21:01:12 +0200 Subject: [PATCH 1/3] Added casting support for oneOfType --- src/validators/oneoftype.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/validators/oneoftype.ts b/src/validators/oneoftype.ts index 9ed666a7..77da019b 100644 --- a/src/validators/oneoftype.ts +++ b/src/validators/oneoftype.ts @@ -11,8 +11,9 @@ import { } from '../utils' export default function oneOfType< - U extends VueProp | Prop, - V = InferType, + D extends InferType, + U extends VueProp | Prop = any, + V = InferType extends unknown ? U : InferType, >(arr: U[]) { if (!isArray(arr)) { throw new TypeError( @@ -52,13 +53,13 @@ export default function oneOfType< if (!hasCustomValidators) { // we got just native objects (ie: Array, Object) // delegate to Vue native prop check - return toType('oneOfType', { - type: nativeChecks, + return toType('oneOfType', { + type: nativeChecks as unknown as PropType, }) } - return toType('oneOfType', { - type: nativeChecks, + return toType('oneOfType', { + type: nativeChecks as unknown as PropType, validator(value) { const err: string[] = [] const valid = arr.some((type) => { From 3bb139e592b5cd3e757bd1a450a2845b3505adf2 Mon Sep 17 00:00:00 2001 From: Victor Garcia Date: Mon, 12 Jul 2021 21:03:53 +0200 Subject: [PATCH 2/3] Fixed some generics --- src/validators/oneoftype.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/validators/oneoftype.ts b/src/validators/oneoftype.ts index 77da019b..237eb692 100644 --- a/src/validators/oneoftype.ts +++ b/src/validators/oneoftype.ts @@ -10,8 +10,12 @@ import { indent, } from '../utils' +type RawLocation = string | { name: string } +const ctor = oneOfType([String, Object]) // Valid +const route = oneOfType([String, Object]) // Valid + export default function oneOfType< - D extends InferType, + D extends V, U extends VueProp | Prop = any, V = InferType extends unknown ? U : InferType, >(arr: U[]) { From 680f2e3b054cb57f4e72622bb8506a5795808120 Mon Sep 17 00:00:00 2001 From: Victor Garcia Date: Mon, 12 Jul 2021 21:04:21 +0200 Subject: [PATCH 3/3] Removed tests --- src/validators/oneoftype.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/validators/oneoftype.ts b/src/validators/oneoftype.ts index 237eb692..e0911989 100644 --- a/src/validators/oneoftype.ts +++ b/src/validators/oneoftype.ts @@ -10,10 +10,6 @@ import { indent, } from '../utils' -type RawLocation = string | { name: string } -const ctor = oneOfType([String, Object]) // Valid -const route = oneOfType([String, Object]) // Valid - export default function oneOfType< D extends V, U extends VueProp | Prop = any,