mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
[mongodb] Fix support for optional fields in $pull and $push (#43892)
This commit is contained in:
parent
498f646452
commit
8987bbd357
5
types/mongodb/index.d.ts
vendored
5
types/mongodb/index.d.ts
vendored
@ -31,6 +31,7 @@
|
||||
// Linus Unnebäck <https://github.com/LinusU>
|
||||
// Richard Bateman <https://github.com/taxilian>
|
||||
// Igor Strebezhev <https://github.com/xamgore>
|
||||
// Valentin Agachi <https://github.com/avaly>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 3.0
|
||||
|
||||
@ -1226,9 +1227,9 @@ export interface Collection<TSchema extends { [key: string]: any } = DefaultSche
|
||||
}
|
||||
|
||||
/** Update Query */
|
||||
type KeysOfAType<TSchema, Type> = { [key in keyof TSchema]: TSchema[key] extends Type ? key : never }[keyof TSchema];
|
||||
type KeysOfAType<TSchema, Type> = { [key in keyof TSchema]: NonNullable<TSchema[key]> extends Type ? key : never }[keyof TSchema];
|
||||
type KeysOfOtherType<TSchema, Type> = {
|
||||
[key in keyof TSchema]: TSchema[key] extends Type ? never : key;
|
||||
[key in keyof TSchema]: NonNullable<TSchema[key]> extends Type ? never : key;
|
||||
}[keyof TSchema];
|
||||
|
||||
type AcceptedFields<TSchema, FieldType, AssignableType> = {
|
||||
|
||||
@ -43,6 +43,8 @@ async function run() {
|
||||
const _b: Bag = b; // b is larger than bag and may contain extra properties
|
||||
});
|
||||
collection.findOne<Bag>({ color: 'white' }).then(b => {
|
||||
b.cost;
|
||||
if (b) {
|
||||
b.cost; // $ExpectType number
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -165,13 +165,13 @@ async function run() {
|
||||
indexTypeResult1.insertedId; // $ExpectType ObjectId
|
||||
// should not remove types of existing fields
|
||||
indexTypeResult1.ops[0].stringField; // $ExpectType string
|
||||
indexTypeResult1.ops[0].numberField; // $ExpectType number
|
||||
indexTypeResult1.ops[0].numberField; // $ExpectType number | undefined
|
||||
// should assign "any" type to any other field
|
||||
indexTypeResult1.ops[0].randomField; // $ExpectType any
|
||||
// should do the same for insertMany
|
||||
indexTypeResultMany1.ops[0]._id; // $ExpectType ObjectId
|
||||
indexTypeResultMany1.insertedIds; // $ExpectType { [key: number]: ObjectId; }
|
||||
indexTypeResultMany1.ops[0].numberField; // $ExpectType number
|
||||
indexTypeResultMany1.ops[0].numberField; // $ExpectType number | undefined
|
||||
indexTypeResultMany1.ops[0].stringField; // $ExpectType string
|
||||
indexTypeResultMany1.ops[0].randomField; // $ExpectType any
|
||||
|
||||
|
||||
@ -112,6 +112,7 @@ async function run() {
|
||||
|
||||
buildUpdateQuery({ $pull: { fruitTags: 'a' } });
|
||||
buildUpdateQuery({ $pull: { fruitTags: { $in: ['a'] } } });
|
||||
buildUpdateQuery({ $pull: { maybeFruitTags: 'apple' } });
|
||||
buildUpdateQuery({ $pull: { 'dot.notation': 1 } });
|
||||
buildUpdateQuery({ $pull: { 'subInterfaceArray.$[]': { $in: ['a'] } } });
|
||||
buildUpdateQuery({ $pull: { subInterfaceArray: { field1: 'a' } }});
|
||||
@ -124,6 +125,7 @@ async function run() {
|
||||
buildUpdateQuery({ $push: { fruitTags: { $each: ['a'], $sort: 1 } } });
|
||||
buildUpdateQuery({ $push: { fruitTags: { $each: ['a'], $sort: -1 } } });
|
||||
buildUpdateQuery({ $push: { fruitTags: { $each: ['a'], $sort: { 'sub.field': -1 } } } });
|
||||
buildUpdateQuery({ $push: { maybeFruitTags: 'apple' } });
|
||||
// buildUpdateQuery({ $push: { fruitTags: { $each: ['stringField'] } } });
|
||||
// buildUpdateQuery({ $push: { 'dot.notation': 1 } });
|
||||
// buildUpdateQuery({ $push: { 'subInterfaceArray.$[]': { $in: ['a'] } } });
|
||||
|
||||
@ -9,5 +9,7 @@ async function run() {
|
||||
collection.stats((err: MongoError, stats: CollStats) => {});
|
||||
|
||||
const stats = await collection.stats();
|
||||
stats.wiredTiger.cache['bytes currently in the cache']; // $ExpectType number
|
||||
if (stats.wiredTiger) {
|
||||
stats.wiredTiger.cache['bytes currently in the cache']; // $ExpectType number
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
|
||||
Loading…
Reference in New Issue
Block a user