-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Closed
Description
Prerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the bug has not already been reported
Mongoose version
6.x.x
Node.js version
14.x
MongoDB server version
5.x
Typescript version (if applicable)
4.8.x
Description
In tsd tests for conn.bulkWrite, accessing res3.validationErrors should be a type error, but TypeScript cannot properly catch it without a cast.
expectError((res3 as typeof res3 & { validationErrors?: unknown }).validationErrors);Without this line, tsd does not fail, and developers might mistakenly think validationErrors exists on ClientBulkWriteResult itself.
Steps to Reproduce
import { createConnection } from 'mongoose';
import { expectError, expectType } from 'tsd';
async function testBulkWrite() {
const conn = createConnection();
const res3 = await conn.bulkWrite([
{ model: 'Test', name: 'updateOne', filter: { name: 'test5' }, update: { $set: { num: 42 } } },
{ model: 'Test', name: 'updateOne', filter: { name: 'test4' }, update: { $set: { num: 'not a number' } } }
], { ordered: false });
// Fails without a cast
expectError(res3.validationErrors);
// Correct workaround
expectError((res3 as typeof res3 & { validationErrors?: unknown }).validationErrors);
}
testBulkWrite();Expected Behavior
TypeScript should fail when trying to access validationErrors directly on ClientBulkWriteResult. The tsd test should enforce that validationErrors only exists under res3.mongoose?.validationErrors.
Metadata
Metadata
Assignees
Labels
No labels