feat(docgen): proper event parsing for typescript

This commit is contained in:
iCrawl
2022-06-10 16:22:11 +02:00
parent 0415300243
commit d4b41dd081
15 changed files with 113 additions and 140 deletions

View File

@@ -1,6 +1,5 @@
/* eslint-disable @typescript-eslint/prefer-ts-expect-error */
import { EventEmitter } from 'node:events';
import type { GatewayVoiceServerUpdateDispatchData, GatewayVoiceStateUpdateDispatchData } from 'discord-api-types/v10';
import { TypedEmitter } from 'tiny-typed-emitter';
import type { CreateVoiceConnectionOptions } from '.';
import {
getVoiceConnection,
@@ -15,7 +14,7 @@ import type { VoiceWebSocket, VoiceUDPSocket } from './networking';
import { Networking, NetworkingState, NetworkingStatusCode } from './networking/Networking';
import { VoiceReceiver } from './receive';
import type { DiscordGatewayAdapterImplementerMethods } from './util/adapter';
import { Awaited, noop } from './util/util';
import { noop } from './util/util';
/**
* The various status codes a voice connection can hold at any one time.
@@ -162,21 +161,10 @@ export type VoiceConnectionState =
| VoiceConnectionReadyState
| VoiceConnectionDestroyedState;
export type VoiceConnectionEvents = {
error: (error: Error) => Awaited<void>;
debug: (message: string) => Awaited<void>;
stateChange: (oldState: VoiceConnectionState, newState: VoiceConnectionState) => Awaited<void>;
} & {
[status in VoiceConnectionStatus]: (
oldState: VoiceConnectionState,
newState: VoiceConnectionState & { status: status },
) => Awaited<void>;
};
/**
* A connection to the voice server of a Guild, can be used to play audio in voice channels.
*/
export class VoiceConnection extends TypedEmitter<VoiceConnectionEvents> {
export class VoiceConnection extends EventEmitter {
/**
* The number of consecutive rejoin attempts. Initially 0, and increments for each rejoin.
* When a connection is successfully established, it resets to 0.
@@ -673,7 +661,6 @@ export class VoiceConnection extends TypedEmitter<VoiceConnectionEvents> {
*
* @param subscription - The removed subscription
*/
// @ts-ignore
private onSubscriptionRemoved(subscription: PlayerSubscription) {
if (this.state.status !== VoiceConnectionStatus.Destroyed && this.state.subscription === subscription) {
this.state = {