🤖 Merge PR #44476 [mongodb] fix return array type for distinct by @HitkoDev

This commit is contained in:
Hitko Development 2020-05-05 12:31:12 +02:00 committed by GitHub
parent 2358d56aa3
commit 374ac503d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View File

@ -29,6 +29,7 @@
// Richard Bateman <https://github.com/taxilian>
// Igor Strebezhev <https://github.com/xamgore>
// Valentin Agachi <https://github.com/avaly>
// HitkoDev <https://github.com/HitkoDev>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// Minimum TypeScript Version: 3.2
@ -44,6 +45,8 @@ import { checkServerIdentity } from 'tls';
// We can use TypeScript Omit once minimum required TypeScript Version is above 3.5
type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
type FlattenIfArray<T> = T extends Array<infer R> ? R : T;
export function connect(uri: string, options?: MongoClientOptions): Promise<MongoClient>;
export function connect(uri: string, callback: MongoCallback<MongoClient>): void;
export function connect(uri: string, options: MongoClientOptions, callback: MongoCallback<MongoClient>): void;
@ -1012,10 +1015,10 @@ export interface Collection<TSchema extends { [key: string]: any } = DefaultSche
deleteOne(filter: FilterQuery<TSchema>, options?: CommonOptions & { bypassDocumentValidation?: boolean }): Promise<DeleteWriteOpResultObject>;
deleteOne(filter: FilterQuery<TSchema>, options: CommonOptions & { bypassDocumentValidation?: boolean }, callback: MongoCallback<DeleteWriteOpResultObject>): void;
/** http://mongodb.github.io/node-mongodb-native/3.1/api/Collection.html#distinct */
distinct<Key extends keyof WithId<TSchema>>(key: Key, callback: MongoCallback<Array<WithId<TSchema>[Key]>>): void;
distinct<Key extends keyof WithId<TSchema>>(key: Key, query: FilterQuery<TSchema>, callback: MongoCallback<Array<WithId<TSchema>[Key]>>): void;
distinct<Key extends keyof WithId<TSchema>>(key: Key, query?: FilterQuery<TSchema>, options?: MongoDistinctPreferences): Promise<Array<WithId<TSchema>[Key]>>;
distinct<Key extends keyof WithId<TSchema>>(key: Key, query: FilterQuery<TSchema>, options: MongoDistinctPreferences, callback: MongoCallback<Array<WithId<TSchema>[Key]>>): void;
distinct<Key extends keyof WithId<TSchema>>(key: Key, callback: MongoCallback<Array<FlattenIfArray<WithId<TSchema>[Key]>>>): void;
distinct<Key extends keyof WithId<TSchema>>(key: Key, query: FilterQuery<TSchema>, callback: MongoCallback<Array<FlattenIfArray<WithId<TSchema>[Key]>>>): void;
distinct<Key extends keyof WithId<TSchema>>(key: Key, query?: FilterQuery<TSchema>, options?: MongoDistinctPreferences): Promise<Array<FlattenIfArray<WithId<TSchema>[Key]>>>;
distinct<Key extends keyof WithId<TSchema>>(key: Key, query: FilterQuery<TSchema>, options: MongoDistinctPreferences, callback: MongoCallback<Array<FlattenIfArray<WithId<TSchema>[Key]>>>): void;
distinct(key: string, callback: MongoCallback<any[]>): void;
distinct(key: string, query: FilterQuery<TSchema>, callback: MongoCallback<any[]>): void;
distinct(key: string, query?: FilterQuery<TSchema>, options?: MongoDistinctPreferences): Promise<any[]>;

View File

@ -6,6 +6,7 @@ async function run() {
interface Collection {
foo: number;
nested: { num: number; };
array: string[];
test: string;
}
@ -35,4 +36,8 @@ async function run() {
collection.distinct('nested.num'); // $ExpectType Promise<any[]>
collection.distinct('nested.num', { foo: 1 }); // $ExpectType Promise<any[]>
collection.distinct('nested.num', { foo: 1 }, { maxTimeMS: 400 }); // $ExpectType Promise<any[]>
collection.distinct('array'); // $ExpectType Promise<string[]>
collection.distinct('array', { foo: 1 }); // $ExpectType Promise<string[]>
collection.distinct('array', { foo: 1 }, { maxTimeMS: 400 }); // $ExpectType Promise<string[]>
}