chore: enable noUncheckedIndexAccess (#7931)

This commit is contained in:
DD
2022-05-18 20:56:42 +03:00
committed by GitHub
parent 993eb74475
commit e2f5a4a494
6 changed files with 7 additions and 6 deletions

View File

@@ -185,7 +185,7 @@ export class Collection<K, V> extends Map<K, V> {
if (!arr.length || !amount) return []; if (!arr.length || !amount) return [];
return Array.from( return Array.from(
{ length: Math.min(amount, arr.length) }, { length: Math.min(amount, arr.length) },
(): V => arr.splice(Math.floor(Math.random() * arr.length), 1)[0], (): V => arr.splice(Math.floor(Math.random() * arr.length), 1)[0]!,
); );
} }
@@ -204,7 +204,7 @@ export class Collection<K, V> extends Map<K, V> {
if (!arr.length || !amount) return []; if (!arr.length || !amount) return [];
return Array.from( return Array.from(
{ length: Math.min(amount, arr.length) }, { length: Math.min(amount, arr.length) },
(): K => arr.splice(Math.floor(Math.random() * arr.length), 1)[0], (): K => arr.splice(Math.floor(Math.random() * arr.length), 1)[0]!,
); );
} }

View File

@@ -481,7 +481,7 @@ export class RequestManager extends EventEmitter {
// Hard-Code Old Message Deletion Exception (2 week+ old messages are a different bucket) // Hard-Code Old Message Deletion Exception (2 week+ old messages are a different bucket)
// https://github.com/discord/discord-api-docs/issues/1295 // https://github.com/discord/discord-api-docs/issues/1295
if (method === RequestMethod.Delete && baseRoute === '/channels/:id/messages/:id') { if (method === RequestMethod.Delete && baseRoute === '/channels/:id/messages/:id') {
const id = /\d{16,19}$/.exec(endpoint)![0]; const id = /\d{16,19}$/.exec(endpoint)![0]!;
const timestamp = DiscordSnowflake.timestampFrom(id); const timestamp = DiscordSnowflake.timestampFrom(id);
if (Date.now() - timestamp > 1000 * 60 * 60 * 24 * 14) { if (Date.now() - timestamp > 1000 * 60 * 60 * 24 * 14) {
exceptions += '/Delete Old Message'; exceptions += '/Delete Old Message';

View File

@@ -97,7 +97,7 @@ export class AudioResource<T = unknown> {
public constructor(edges: readonly Edge[], streams: readonly Readable[], metadata: T, silencePaddingFrames: number) { public constructor(edges: readonly Edge[], streams: readonly Readable[], metadata: T, silencePaddingFrames: number) {
this.edges = edges; this.edges = edges;
this.playStream = streams.length > 1 ? (pipeline(streams, noop) as any as Readable) : streams[0]; this.playStream = streams.length > 1 ? (pipeline(streams, noop) as any as Readable) : streams[0]!;
this.metadata = metadata; this.metadata = metadata;
this.silencePaddingFrames = silencePaddingFrames; this.silencePaddingFrames = silencePaddingFrames;

View File

@@ -133,7 +133,7 @@ export class VoiceUDPSocket extends TypedEmitter<VoiceUDPSocketEvents> {
const counter = buffer.readUInt32LE(0); const counter = buffer.readUInt32LE(0);
const index = this.keepAlives.findIndex(({ value }) => value === counter); const index = this.keepAlives.findIndex(({ value }) => value === counter);
if (index === -1) return; if (index === -1) return;
this.ping = Date.now() - this.keepAlives[index].timestamp; this.ping = Date.now() - this.keepAlives[index]!.timestamp;
// Delete all keep alives up to and including the received one // Delete all keep alives up to and including the received one
this.keepAlives.splice(0, index); this.keepAlives.splice(0, index);
} }

View File

@@ -134,7 +134,7 @@ export class VoiceReceiver {
const headerExtensionLength = packet.readUInt16BE(2); const headerExtensionLength = packet.readUInt16BE(2);
let offset = 4; let offset = 4;
for (let i = 0; i < headerExtensionLength; i++) { for (let i = 0; i < headerExtensionLength; i++) {
const byte = packet[offset]; const byte = packet[offset]!;
offset++; offset++;
if (byte === 0) continue; if (byte === 0) continue;
offset += 1 + (byte >> 4); offset += 1 + (byte >> 4);

View File

@@ -13,6 +13,7 @@
"noUnusedParameters": true, "noUnusedParameters": true,
"strict": true, "strict": true,
"useUnknownInCatchVariables": true, "useUnknownInCatchVariables": true,
"noUncheckedIndexedAccess": true,
// Modules // Modules
"module": "CommonJS", "module": "CommonJS",