Skip to content

tsd test for bulkWrite does not properly assert validationErrors type error #15768

@THE-Amrit-mahto-05

Description

@THE-Amrit-mahto-05

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions