From 2446ff525145afa3d5b4b5e822c3e7d8b010a4c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Rom=C3=A1n?= Date: Sat, 3 Jul 2021 14:25:35 +0200 Subject: [PATCH] refactor(Util): make class extend `null` (#6000) --- src/util/DataResolver.js | 6 +----- src/util/SnowflakeUtil.js | 6 +----- src/util/Structures.js | 6 +----- src/util/Util.js | 6 +----- typings/index.d.ts | 12 ++++++++---- 5 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/util/DataResolver.js b/src/util/DataResolver.js index 821e17981..20d4abc34 100644 --- a/src/util/DataResolver.js +++ b/src/util/DataResolver.js @@ -11,11 +11,7 @@ const Invite = require('../structures/Invite'); * The DataResolver identifies different objects and tries to resolve a specific piece of information from them. * @private */ -class DataResolver { - constructor() { - throw new Error(`The ${this.constructor.name} class may not be instantiated.`); - } - +class DataResolver extends null { /** * Data that can be resolved to give an invite code. This can be: * * An invite code diff --git a/src/util/SnowflakeUtil.js b/src/util/SnowflakeUtil.js index 2153a0ccf..656e32d60 100644 --- a/src/util/SnowflakeUtil.js +++ b/src/util/SnowflakeUtil.js @@ -9,11 +9,7 @@ let INCREMENT = 0; /** * A container for useful snowflake-related methods. */ -class SnowflakeUtil { - constructor() { - throw new Error(`The ${this.constructor.name} class may not be instantiated.`); - } - +class SnowflakeUtil extends null { /** * A Twitter snowflake, except the epoch is 2015-01-01T00:00:00.000Z * ``` diff --git a/src/util/Structures.js b/src/util/Structures.js index edfe79e2d..33343e7e1 100644 --- a/src/util/Structures.js +++ b/src/util/Structures.js @@ -31,11 +31,7 @@ /** * Allows for the extension of built-in Discord.js structures that are instantiated by {@link BaseManager Managers}. */ -class Structures { - constructor() { - throw new Error(`The ${this.constructor.name} class may not be instantiated.`); - } - +class Structures extends null { /** * Retrieves a structure class. * @param {string} structure Name of the structure to retrieve diff --git a/src/util/Util.js b/src/util/Util.js index 125c3101f..b6cc50e30 100644 --- a/src/util/Util.js +++ b/src/util/Util.js @@ -10,11 +10,7 @@ const isObject = d => typeof d === 'object' && d !== null; /** * Contains various general-purpose utility methods. */ -class Util { - constructor() { - throw new Error(`The ${this.constructor.name} class may not be instantiated.`); - } - +class Util extends null { /** * Flatten an object. Any properties that are collections will get converted to an array of keys. * @param {Object} obj The object to flatten. diff --git a/typings/index.d.ts b/typings/index.d.ts index 919dc2113..3ec2bbcf5 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -812,7 +812,8 @@ declare module 'discord.js' { PremiumTiers: typeof PremiumTiers; }; - export class DataResolver { + export class DataResolver extends null { + private constructor(); public static resolveBase64(data: Base64Resolvable): string; public static resolveCode(data: string, regx: RegExp): string; public static resolveFile(resource: BufferResolvable | Stream): Promise; @@ -1855,7 +1856,8 @@ declare module 'discord.js' { public once(event: 'shardCreate', listener: (shard: Shard) => Awaited): this; } - export class SnowflakeUtil { + export class SnowflakeUtil extends null { + private constructor(); public static deconstruct(snowflake: Snowflake): DeconstructedSnowflake; public static generate(timestamp?: number | Date): Snowflake; public static readonly EPOCH: number; @@ -1892,7 +1894,8 @@ declare module 'discord.js' { public type: 'store'; } - export class Structures { + export class Structures extends null { + private constructor(); public static get(structure: K): Extendable[K]; public static get(structure: string): (...args: any[]) => void; public static extend( @@ -2052,7 +2055,8 @@ declare module 'discord.js' { public static resolve(bit?: BitFieldResolvable): number; } - export class Util { + export class Util extends null { + private constructor(); public static basename(path: string, ext?: string): string; public static binaryToID(num: string): Snowflake; public static cleanContent(str: string, channel: Channel): string;