Skip to content

Commit

Permalink
Fixed InferSchemaType nullable arrays type inference
Browse files Browse the repository at this point in the history
  • Loading branch information
lpizzinidev committed Sep 17, 2022
1 parent 586c86f commit ebe610e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions test/types/schema.test.ts
Expand Up @@ -741,3 +741,32 @@ function pluginOptions() {
schema.plugin<any, SomePluginOptions>(pluginFunction2, { option2: 0 });
expectError(schema.plugin<any, SomePluginOptions>(pluginFunction2, {})); // should error because "option2" is not optional
}

function gh12420() {
const TestSchema = new Schema(
{
comments: { type: [String], required: false },
reference: {
type: [
{
type: { type: String, required: false },
value: { type: String, required: false }
}
],
required: false
}
},
{
collection: 'tests',
timestamps: false
}
);

expectType<{
comments?: string[],
reference?: {
type?: string,
value?: string
}[]
}>({} as InferSchemaType<typeof TestSchema>);
}
2 changes: 1 addition & 1 deletion types/inferschematype.d.ts
Expand Up @@ -69,7 +69,7 @@ type IsPathRequired<P, TypeKey extends TypeKeyBaseType> =
P extends { required: true | [true, string | undefined] } | ArrayConstructor | any[]
? true
: P extends (Record<TypeKey, ArrayConstructor | any[]>)
? P extends { default: undefined }
? P extends { default: undefined } | { required: false }
? false
: true
: P extends (Record<TypeKey, any>)
Expand Down

0 comments on commit ebe610e

Please sign in to comment.