#16519·mongoose

Types: Type narrowing is lost for projection when chained with lean()

Author: akostivCreated Sep 21, 2026Updated Sep 22, 2026

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

9.10.1

Node.js version

26.9.0

MongoDB server version

7.6.0

Typescript version (if applicable)

7.0.2

Description

Issue https://github.com/Automattic/mongoose/issues/15545 added support for type narrowing for projection in findOne and find but it is lost when chained with lean()

Steps to Reproduce

typescript
import { model, Schema } from 'mongoose';

interface IUser { name: string; age: number; email: string }
const User = model<IUser>('User', new Schema<IUser>({ name: String, age: Number, email: String }));

// Narrowed
const a = await User.findOne({}, { name: 1 });
a!.age; // Error

// Narrowed
const b = await User.findOne({}, { name: 1 }, { lean: true });
b!.age; // Error

// Not narrowed (lean via chaining)
const c = await User.findOne({}, { name: 1 }).lean();
c!.age; // No error

Expected Behavior

No response