Make InferType from ArraySchema compatible with Array type (#42351)

This commit is contained in:
Maurice de Beijer
2020-02-14 09:15:58 -08:00
committed by GitHub
parent 704b916b49
commit 46b1c41f67
2 changed files with 7 additions and 1 deletions
+1 -1
View File
@@ -511,5 +511,5 @@ type KeyOfUndefined<T> = {
type Id<T> = { [K in keyof T]: T[K] };
type RequiredProps<T> = Pick<T, Exclude<keyof T, KeyOfUndefined<T>>>;
type NotRequiredProps<T> = Partial<Pick<T, KeyOfUndefined<T>>>;
type InnerInferType<T> = Id<NotRequiredProps<T> & RequiredProps<T>>;
type InnerInferType<T> = T extends Array<infer T> ? T[] : Id<NotRequiredProps<T> & RequiredProps<T>> ;
type InferredArrayType<T> = T extends Array<infer U> ? U : T;
+6
View File
@@ -823,3 +823,9 @@ function wrapper<T>(b: boolean, msx: MixedSchema<T>): MixedSchema<T> {
const resultingSchema1 = wrapper<string | number>(false, yup.mixed().oneOf(['1', 2])); // $ExpectType MixedSchema<string | number>
const resultingSchema2 = wrapper<string | number>(true, yup.mixed().oneOf(['1', 2])); // $ExpectType MixedSchema<string | number | null>
const arrayOfStringsSchema = yup.array().of(yup.string());
type ArrayOfStrings = yup.InferType<typeof arrayOfStringsSchema>;
function returnTheArray(data: ArrayOfStrings): any[] {
return data;
}