mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
[mongoose] Fix _id type of lean() result (#43039)
This commit is contained in:
parent
0ea91f4387
commit
460862aa68
2
types/mongoose/index.d.ts
vendored
2
types/mongoose/index.d.ts
vendored
@ -79,7 +79,7 @@ declare module "mongoose" {
|
||||
type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
|
||||
|
||||
/* Helper type to extract a definition type from a Document type */
|
||||
type DocumentDefinition<T> = Omit<T, keyof Document> & { _id: mongodb.ObjectId };
|
||||
type DocumentDefinition<T> = Omit<T, Exclude<keyof Document, '_id'>>;
|
||||
|
||||
/**
|
||||
* Gets and optionally overwrites the function used to pluralize collection names
|
||||
|
||||
@ -1303,14 +1303,14 @@ query.lean(false)
|
||||
query.lean({})
|
||||
|
||||
interface Location1 extends mongoose.Document {
|
||||
_id: mongoose.Types.ObjectId;
|
||||
name: string;
|
||||
address: string;
|
||||
rating: number;
|
||||
reviews: any[];
|
||||
};
|
||||
var locQuery = <mongoose.DocumentQuery<Location1, Location1>>{};
|
||||
async function leanTests() {
|
||||
var location = await locQuery.lean().exec();
|
||||
var loc1Query = <mongoose.DocumentQuery<Location1, Location1>>{};
|
||||
loc1Query.lean().then(location => {
|
||||
if (location) {
|
||||
// $ExpectType ObjectId
|
||||
location._id;
|
||||
@ -1323,7 +1323,28 @@ async function leanTests() {
|
||||
// $ExpectError
|
||||
location.save();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
interface Location2 extends mongoose.Document {
|
||||
_id: string;
|
||||
name: string;
|
||||
rating: number;
|
||||
};
|
||||
var loc2Query = <mongoose.DocumentQuery<Location2, Location2>>{};
|
||||
loc2Query.lean().then(location => {
|
||||
if (location) {
|
||||
// $ExpectType string
|
||||
location._id;
|
||||
// $ExpectType string
|
||||
location.name;
|
||||
// $ExpectType number
|
||||
location.rating;
|
||||
// $ExpectError
|
||||
location.unknown;
|
||||
// $ExpectError
|
||||
location.save();
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* section schema/array.js
|
||||
@ -1965,6 +1986,7 @@ MongoModel.find({
|
||||
.exec();
|
||||
/* practical example */
|
||||
interface Location extends mongoose.Document {
|
||||
_id: mongoose.Types.ObjectId;
|
||||
name: string;
|
||||
address: string;
|
||||
rating: number;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user