Skip to content

Commit

Permalink
revert(BitField): ⏪ Bring back-compatibility after BitField serializa…
Browse files Browse the repository at this point in the history
…tion (#5910)
  • Loading branch information
DraftProducts committed Jun 28, 2021
1 parent dc671c8 commit 0a0630c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/util/BitField.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ class BitField {
/**
* Data that can be resolved to give a bitfield. This can be:
* * A bit number (this can be a number literal or a value taken from {@link BitField.FLAGS})
* * A string bit number
* * An instance of BitField
* * An Array of BitFieldResolvable
* @typedef {number|bigint|BitField|BitFieldResolvable[]} BitFieldResolvable
* @typedef {number|string|bigint|BitField|BitFieldResolvable[]} BitFieldResolvable
*/

/**
Expand All @@ -144,7 +145,10 @@ class BitField {
if (typeof defaultBit === typeof bit && bit >= defaultBit) return bit;
if (bit instanceof BitField) return bit.bitfield;
if (Array.isArray(bit)) return bit.map(p => this.resolve(p)).reduce((prev, p) => prev | p, defaultBit);
if (typeof bit === 'string' && typeof this.FLAGS[bit] !== 'undefined') return this.FLAGS[bit];
if (typeof bit === 'string') {
if (typeof this.FLAGS[bit] !== 'undefined') return this.FLAGS[bit];
if (!isNaN(bit)) return typeof defaultBit === 'bigint' ? BigInt(bit) : Number(bit);
}
throw new RangeError('BITFIELD_INVALID', bit);
}
}
Expand Down
5 changes: 3 additions & 2 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ declare module 'discord.js' {
public valueOf(): N;
public [Symbol.iterator](): IterableIterator<S>;
public static FLAGS: unknown;
public static resolve(bit?: BitFieldResolvable<any, number | bigint>): number | bigint;
public static resolve(bit?: BitFieldResolvable<S, N>): number | bigint;
}

export class ButtonInteraction extends MessageComponentInteraction {
Expand Down Expand Up @@ -2874,9 +2874,10 @@ declare module 'discord.js' {
}

type BitFieldResolvable<T extends string, N extends number | bigint> =
| RecursiveReadonlyArray<T | N | Readonly<BitField<T, N>>>
| RecursiveReadonlyArray<T | N | `${bigint}` | Readonly<BitField<T, N>>>
| T
| N
| `${bigint}`
| Readonly<BitField<T, N>>;

type BufferResolvable = Buffer | string;
Expand Down

0 comments on commit 0a0630c

Please sign in to comment.