diff --git a/index.d.ts b/index.d.ts index 3184e817904..977c28a4452 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1704,8 +1704,9 @@ declare module "mongoose" { export type DocumentDefinition = Omit>; - type FunctionPropertyNames = { - [K in keyof T]: T[K] extends Function ? K : never + type FunctionPropertyNames = { + // The 1 & T[K] check comes from: https://stackoverflow.com/questions/55541275/typescript-check-for-the-any-type + [K in keyof T]: 0 extends (1 & T[K]) ? never : (T[K] extends Function ? K : never) }[keyof T]; export type LeanDocument = Omit>, FunctionPropertyNames>; diff --git a/test/typescript/leanDocuments.ts b/test/typescript/leanDocuments.ts index 6c6dd5b2859..a05775138ab 100644 --- a/test/typescript/leanDocuments.ts +++ b/test/typescript/leanDocuments.ts @@ -5,6 +5,7 @@ const schema: Schema = new Schema({ name: { type: 'String' } }); interface ITest extends Document { _id?: Types.ObjectId, name?: string; + mixed?: any; testMethod: () => number; } @@ -24,6 +25,8 @@ void async function main() { await _doc.save(); _doc.testMethod(); + _doc.name = 'test'; + _doc.mixed = 42; const hydrated = Test.hydrate(_doc); await hydrated.save();