From d5831df7b18e3b71c9ad7057b85fc3c84aa7c609 Mon Sep 17 00:00:00 2001 From: 1Computer1 Date: Tue, 17 Sep 2019 18:53:00 -0400 Subject: [PATCH] fix: typings for this-polymorphism of collections (#3472) * Fix typings for this-polymorphism of collections * Update index.d.ts Co-authored-by: Crawl --- typings/index.d.ts | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index d71dde4d7..811aa78ae 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1,5 +1,5 @@ declare module 'discord.js' { - import BaseCollection, { CollectionConstructor } from '@discordjs/collection'; + import BaseCollection from '@discordjs/collection'; import { EventEmitter } from 'events'; import { Stream, Readable, Writable } from 'stream'; import { ChildProcess } from 'child_process'; @@ -313,6 +313,12 @@ declare module 'discord.js' { } export class Collection extends BaseCollection { + public flatMap(fn: (value: V, key: K, collection: this) => Collection): Collection; + public flatMap(fn: (this: This, value: V, key: K, collection: this) => Collection, thisArg: This): Collection; + public flatMap(fn: (value: V, key: K, collection: this) => Collection, thisArg?: unknown): Collection; + public mapValues(fn: (value: V, key: K, collection: this) => T): Collection; + public mapValues(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): Collection; + public mapValues(fn: (value: V, key: K, collection: this) => T, thisArg?: unknown): Collection; public toJSON(): object; } @@ -1684,13 +1690,37 @@ declare module 'discord.js' { export class DataStore, R = any> extends Collection { constructor(client: Client, iterable: Iterable, holds: VConstructor); - public static readonly [Symbol.species]: CollectionConstructor; public client: Client; public holds: VConstructor; public add(data: any, cache?: boolean, { id, extras }?: { id: K, extras: any[] }): V; public remove(key: K): void; public resolve(resolvable: R): V | null; public resolveID(resolvable: R): K | null; + // Don't worry about those bunch of ts-ignores here, this is intended https://github.com/microsoft/TypeScript/issues/1213 + // @ts-ignore + public filter(fn: (value: V, key: K, collection: this) => boolean): Collection; + // @ts-ignore + public filter(fn: (this: T, value: V, key: K, collection: this) => boolean, thisArg: T): Collection; + // @ts-ignore + public filter(fn: (value: V, key: K, collection: this) => boolean, thisArg?: unknown): Collection; + // @ts-ignore + public partition(fn: (value: V, key: K, collection: this) => boolean): [Collection, Collection]; + // @ts-ignore + public partition(fn: (this: T, value: V, key: K, collection: this) => boolean, thisArg: T): [Collection, Collection]; + // @ts-ignore + public partition(fn: (value: V, key: K, collection: this) => boolean, thisArg?: unknown): [Collection, Collection]; + public flatMap(fn: (value: V, key: K, collection: this) => Collection): Collection; + public flatMap(fn: (this: This, value: V, key: K, collection: this) => Collection, thisArg: This): Collection; + public flatMap(fn: (value: V, key: K, collection: this) => Collection, thisArg?: unknown): Collection; + public mapValues(fn: (value: V, key: K, collection: this) => T): Collection; + public mapValues(fn: (this: This, value: V, key: K, collection: this) => T, thisArg: This): Collection; + public mapValues(fn: (value: V, key: K, collection: this) => T, thisArg?: unknown): Collection; + // @ts-ignore + public clone(): Collection; + // @ts-ignore + public concat(...collections: Collection[]): Collection; + // @ts-ignore + public sorted(compareFunction: (firstValue: V, secondValue: V, firstKey: K, secondKey: K) => number): Collection; } export class GuildEmojiRoleStore extends OverridableDataStore {