diff --git a/index.d.ts b/index.d.ts index a87dae0a276..59e53478e7b 100644 --- a/index.d.ts +++ b/index.d.ts @@ -475,7 +475,7 @@ declare module "mongoose" { getChanges(): UpdateQuery; /** The string version of this documents _id. */ - id: string; + id?: string; /** Signal that we desire an increment of this documents version. */ increment(): this; diff --git a/test/typescript/models.ts b/test/typescript/models.ts index 6184796c642..4b4bb75a63f 100644 --- a/test/typescript/models.ts +++ b/test/typescript/models.ts @@ -1,19 +1,37 @@ import { Schema, Document, Model, connection } from 'mongoose'; -interface ITest extends Document { - foo: string; +function conventionalSyntax(): void { + interface ITest extends Document { + foo: string; + } + + const TestSchema = new Schema({ + foo: { type: String, required: true }, + }); + + const Test = connection.model('Test', TestSchema); + + const bar = (SomeModel: Model) => console.log(SomeModel); + + bar(Test); } -const TestSchema = new Schema({ - foo: { type: String, required: true }, -}); +function tAndDocSyntax(): void { + interface ITest { + id: number; + foo: string; + } + + const TestSchema = new Schema({ + foo: { type: String, required: true }, + }); -const Test = connection.model('Test', TestSchema); + const Test = connection.model('Test', TestSchema); -const bar = (SomeModel: Model) => // <<<< error here - console.log(SomeModel); + const aggregated: Promise = Test.aggregate([]).then(res => res[0]); -bar(Test); + const bar = (SomeModel: Model) => console.log(SomeModel); +} const ExpiresSchema = new Schema({ ttl: { @@ -22,8 +40,6 @@ const ExpiresSchema = new Schema({ }, }); -const aggregated: Promise = Test.aggregate([]).then(res => res[0]); - interface IProject extends Document { name: String; }