From 7c30dc8eff699e8e5b75a6f8a0b257c72d8f70be Mon Sep 17 00:00:00 2001 From: Moreton Bay RC Date: Wed, 31 Jan 2018 10:36:04 +1000 Subject: [PATCH] Fix type inference for arrays --- types/yup/index.d.ts | 8 ++++---- types/yup/yup-tests.ts | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/types/yup/index.d.ts b/types/yup/index.d.ts index 0332e0966d..844b1a1f8e 100644 --- a/types/yup/index.d.ts +++ b/types/yup/index.d.ts @@ -118,12 +118,12 @@ export interface DateSchema extends Schema { } export interface ArraySchemaConstructor { - (): ArraySchema; - new(): ArraySchema; + (): ArraySchema<{}>; + new(): ArraySchema<{}>; } export interface ArraySchema extends Schema { - of(type: Schema): ArraySchema; + of(type: Schema): ArraySchema; min(limit: number | Ref, message?: string): ArraySchema; max(limit: number | Ref, message?: string): ArraySchema; ensure(): ArraySchema; @@ -132,7 +132,7 @@ export interface ArraySchema extends Schema { export interface ObjectSchemaConstructor { (fields?: T): ObjectSchema; - new (): ObjectSchema; + new (): ObjectSchema<{}>; } export interface ObjectSchema extends Schema { diff --git a/types/yup/yup-tests.ts b/types/yup/yup-tests.ts index 0fa05ac47d..b1a4293915 100644 --- a/types/yup/yup-tests.ts +++ b/types/yup/yup-tests.ts @@ -266,6 +266,7 @@ interface MyInterface { stringField: string; numberField: number; subFields: SubInterface; + arrayField: string[]; } interface SubInterface { @@ -278,6 +279,7 @@ const typedSchema = yup.object().shape({ subFields: yup.object().shape({ testField: yup.string().required(), }).required(), + arrayField: yup.array().of(yup.string()).required(), }); const testObject = { @@ -286,6 +288,7 @@ const testObject = { subFields: { testField: "test2" }, + arrayField: ["hi"], }; typedSchema.validate(testObject); @@ -296,6 +299,7 @@ const untypedSchema = yup.object().shape({ subFields: yup.object().shape({ testField: yup.string().required(), }).required(), + arrayField: yup.array().of(yup.string()).required(), }); untypedSchema.validate(testObject);