Skip to content

Commit

Permalink
Pass parameters to create function to recreate issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sbahman committed May 3, 2024
1 parent a012b6a commit 38a386e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 29 deletions.
21 changes: 20 additions & 1 deletion src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class AdminLogEntity {
public username?: string;
}

interface AdminLogSaveParams {
username?: string,
}

async function main() {
await mongoose.connect(`mongodb://localhost:27017/`, {
dbName: 'verifyMASTER',
Expand All @@ -19,11 +23,26 @@ async function main() {
const adminLogModel: ReturnModelType<typeof AdminLogEntity, BeAnObject> = 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();

53 changes: 25 additions & 28 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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/**/*"]
}

0 comments on commit 38a386e

Please sign in to comment.