diff --git a/test/types/schema.test.ts b/test/types/schema.test.ts index de80dc0de73..b919e68e6ec 100644 --- a/test/types/schema.test.ts +++ b/test/types/schema.test.ts @@ -1424,3 +1424,21 @@ function gh14496() { } }); } + +function gh14367() { + const UserSchema = new Schema({ + counts: [Schema.Types.Number], + roles: [Schema.Types.String], + dates: [Schema.Types.Date], + flags: [Schema.Types.Boolean] + }); + + type IUser = InferSchemaType; + + const x: IUser = { + counts: [12], + roles: ['test'], + dates: [new Date('2016-06-01')], + flags: [true] + }; +} diff --git a/types/inferschematype.d.ts b/types/inferschematype.d.ts index bdd56790a3d..ff1e92b7831 100644 --- a/types/inferschematype.d.ts +++ b/types/inferschematype.d.ts @@ -198,15 +198,27 @@ type IsSchemaTypeFromBuiltinClass = T extends (typeof String) ? true : T extends (typeof Schema.Types.Decimal128) ? true - : T extends Types.ObjectId + : T extends (typeof Schema.Types.String) ? true - : T extends Types.Decimal128 + : T extends (typeof Schema.Types.Number) ? true - : T extends Buffer + : T extends (typeof Schema.Types.Date) ? true - : T extends (typeof Schema.Types.Mixed) + : T extends (typeof Schema.Types.Boolean) ? true - : IfEquals; + : T extends (typeof Schema.Types.Buffer) + ? true + : T extends Types.ObjectId + ? true + : T extends Types.Decimal128 + ? true + : T extends Buffer + ? true + : T extends NativeDate + ? true + : T extends (typeof Schema.Types.Mixed) + ? true + : IfEquals; /** * @summary Resolve path type by returning the corresponding type.