From 38a386e6e8bb2f6988b8de9e2ab02d14061839d5 Mon Sep 17 00:00:00 2001 From: Severin Bahman Date: Fri, 3 May 2024 18:58:44 +0200 Subject: [PATCH] Pass parameters to create function to recreate issue --- src/test.ts | 21 +++++++++++++++++++- tsconfig.json | 53 ++++++++++++++++++++++++--------------------------- 2 files changed, 45 insertions(+), 29 deletions(-) diff --git a/src/test.ts b/src/test.ts index 27c69a2..cccca92 100644 --- a/src/test.ts +++ b/src/test.ts @@ -10,6 +10,10 @@ class AdminLogEntity { public username?: string; } +interface AdminLogSaveParams { + username?: string, +} + async function main() { await mongoose.connect(`mongodb://localhost:27017/`, { dbName: 'verifyMASTER', @@ -19,11 +23,26 @@ async function main() { const adminLogModel: ReturnModelType = getModelForClass(AdminLogEntity); const options: mongoose.CreateOptions = { session }; - const adminLogEntity = await adminLogModel.create({}, options); + const params = { + username: 'a', + } + + const params2: AdminLogSaveParams = { + username: 'b', + } + + // This does not work + const adminLogEntity = await adminLogModel.create(params, options); + // But the next 2 lines work + const adminLogEntity2 = await adminLogModel.create(params2, options); + const adminLogEntity3 = await adminLogModel.create({ username: 'a' }, options); console.log('entity', adminLogEntity); + console.log('entity2', adminLogEntity2); + console.log('entity3', adminLogEntity3); await mongoose.disconnect(); } main(); + diff --git a/tsconfig.json b/tsconfig.json index 24bde6b..fc70ea9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,30 +1,27 @@ { - "compileOnSave": true, - "typeAcquisition": { - "enable": true - }, - "compilerOptions": { - "experimentalDecorators": true, - "emitDecoratorMetadata": true, - "declarationMap": true, - "outDir": "lib", - "moduleResolution": "node", - "target": "ES2021", - "module": "commonjs", - "newLine": "LF", - "sourceMap": true, - "removeComments": true, - "strict": true, - "allowUnreachableCode": false, - "pretty": true, - "declaration": true, - "incremental": true, - "tsBuildInfoFile": ".tsbuildinfo", - "lib": [ - "esnext" - ] - }, - "include": [ - "src/**/*" - ] + "compileOnSave": true, + "typeAcquisition": { + "enable": true + }, + "compilerOptions": { + "experimentalDecorators": true, + "emitDecoratorMetadata": true, + "declarationMap": true, + "outDir": "lib", + "moduleResolution": "node", + "target": "ES2021", + "module": "commonjs", + "newLine": "LF", + "sourceMap": true, + "removeComments": true, + "strict": true, + "strictPropertyInitialization": false, + "allowUnreachableCode": false, + "pretty": true, + "declaration": true, + "incremental": true, + "tsBuildInfoFile": ".tsbuildinfo", + "lib": ["esnext"] + }, + "include": ["src/**/*"] }