Skip to content

Commit 8cfadb6

Browse files
authored
docs: Remove duplicate APIEmoji (#9880)
* types: remove duplicate type definition * chore: add `Emoji` to method * types(resolvePartialEmoji): overload method
1 parent 7422d9f commit 8cfadb6

File tree

4 files changed

+40
-18
lines changed

4 files changed

+40
-18
lines changed

packages/discord.js/src/structures/Emoji.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@
33
const { DiscordSnowflake } = require('@sapphire/snowflake');
44
const Base = require('./Base');
55

6-
/**
7-
* Represents raw emoji data from the API
8-
* @typedef {APIEmoji} RawEmoji
9-
* @property {?Snowflake} id The emoji's id
10-
* @property {?string} name The emoji's name
11-
* @property {?boolean} animated Whether the emoji is animated
12-
*/
13-
146
/**
157
* Represents an emoji, see {@link GuildEmoji} and {@link ReactionEmoji}.
168
* @extends {Base}
@@ -101,8 +93,3 @@ class Emoji extends Base {
10193
}
10294

10395
exports.Emoji = Emoji;
104-
105-
/**
106-
* @external APIEmoji
107-
* @see {@link https://discord.com/developers/docs/resources/emoji#emoji-object}
108-
*/

packages/discord.js/src/util/Util.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,21 @@ async function fetchRecommendedShardCount(token, { guildsPerShard = 1_000, multi
7979
return Math.ceil((shards * (1_000 / guildsPerShard)) / multipleOf) * multipleOf;
8080
}
8181

82+
/**
83+
* A partial emoji object.
84+
* @typedef {Object} PartialEmoji
85+
* @property {boolean} animated Whether the emoji is animated
86+
* @property {Snowflake|undefined} id The id of the emoji
87+
* @property {string} name The name of the emoji
88+
*/
89+
8290
/**
8391
* Parses emoji info out of a string. The string must be one of:
8492
* * A UTF-8 emoji (no id)
8593
* * A URL-encoded UTF-8 emoji (no id)
8694
* * A Discord custom emoji (`<:name:id>` or `<a:name:id>`)
8795
* @param {string} text Emoji string to parse
88-
* @returns {APIEmoji} Object with `animated`, `name`, and `id` properties
96+
* @returns {?PartialEmoji}
8997
*/
9098
function parseEmoji(text) {
9199
if (text.includes('%')) text = decodeURIComponent(text);
@@ -94,10 +102,16 @@ function parseEmoji(text) {
94102
return match && { animated: Boolean(match[1]), name: match[2], id: match[3] };
95103
}
96104

105+
/**
106+
* A partial emoji object with only an id.
107+
* @typedef {Object} PartialEmojiOnlyId
108+
* @property {Snowflake} id The id of the emoji
109+
*/
110+
97111
/**
98112
* Resolves a partial emoji object from an {@link EmojiIdentifierResolvable}, without checking a Client.
99-
* @param {EmojiIdentifierResolvable} emoji Emoji identifier to resolve
100-
* @returns {?RawEmoji}
113+
* @param {Emoji|EmojiIdentifierResolvable} emoji Emoji identifier to resolve
114+
* @returns {?(PartialEmoji|PartialEmojiOnlyId)} Suppling a snowflake yields `PartialEmojiOnlyId`.
101115
* @private
102116
*/
103117
function resolvePartialEmoji(emoji) {

packages/discord.js/typings/index.d.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3202,9 +3202,10 @@ export function makeError(obj: MakeErrorOptions): Error;
32023202
export function makePlainError(err: Error): MakeErrorOptions;
32033203
export function mergeDefault(def: unknown, given: unknown): unknown;
32043204
export function moveElementInArray(array: unknown[], element: unknown, newIndex: number, offset?: boolean): number;
3205-
export function parseEmoji(text: string): { animated: boolean; name: string; id: Snowflake | null } | null;
3205+
export function parseEmoji(text: string): PartialEmoji | null;
32063206
export function resolveColor(color: ColorResolvable): number;
3207-
export function resolvePartialEmoji(emoji: EmojiIdentifierResolvable): Partial<APIPartialEmoji> | null;
3207+
export function resolvePartialEmoji(emoji: Snowflake): PartialEmojiOnlyId;
3208+
export function resolvePartialEmoji(emoji: Emoji | EmojiIdentifierResolvable): PartialEmoji | null;
32083209
export function verifyString(data: string, error?: typeof Error, errorMessage?: string, allowEmpty?: boolean): string;
32093210
export function setPosition<T extends Channel | Role>(
32103211
item: T,
@@ -6159,6 +6160,16 @@ export interface PartialChannelData {
61596160
rateLimitPerUser?: number;
61606161
}
61616162

6163+
export interface PartialEmoji {
6164+
animated: boolean;
6165+
id: Snowflake | undefined;
6166+
name: string;
6167+
}
6168+
6169+
export interface PartialEmojiOnlyId {
6170+
id: Snowflake;
6171+
}
6172+
61626173
export type Partialize<
61636174
T extends AllowedPartial,
61646175
NulledKeys extends keyof T | null = null,

packages/discord.js/typings/index.test-d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ import {
181181
PartialGuildMember,
182182
PartialMessage,
183183
PartialMessageReaction,
184+
resolvePartialEmoji,
185+
PartialEmojiOnlyId,
186+
Emoji,
187+
PartialEmoji,
184188
} from '.';
185189
import { expectAssignable, expectNotAssignable, expectNotType, expectType } from 'tsd';
186190
import type { ContextMenuCommandBuilder, SlashCommandBuilder } from '@discordjs/builders';
@@ -2363,3 +2367,9 @@ expectType<true>(partialUser.partial);
23632367
expectType<null>(partialUser.username);
23642368
expectType<null>(partialUser.tag);
23652369
expectType<null>(partialUser.discriminator);
2370+
2371+
declare const emoji: Emoji;
2372+
{
2373+
expectType<PartialEmojiOnlyId>(resolvePartialEmoji('12345678901234567'));
2374+
expectType<PartialEmoji | null>(resolvePartialEmoji(emoji));
2375+
}

0 commit comments

Comments
 (0)