From 5735e09738fb05cbebffcd23c1fc083bba6b6b7f Mon Sep 17 00:00:00 2001 From: taichi221228 Date: Thu, 2 May 2024 13:22:56 +0900 Subject: [PATCH] Refactor emoji utilities by introducing type aliases This commit introduces type aliases to the emoji utilities in JavaScript code, specifically `RawEmoji` and `GetDataArgs`. These changes help to simplify function signatures. By extracting complex types into separate type aliases, the code readability has been improved significantly. --- .../mastodon/features/emoji/emoji_utils.ts | 44 +++++++------------ 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/app/javascript/mastodon/features/emoji/emoji_utils.ts b/app/javascript/mastodon/features/emoji/emoji_utils.ts index cd1b463a0a8..bf5605ebe7a 100644 --- a/app/javascript/mastodon/features/emoji/emoji_utils.ts +++ b/app/javascript/mastodon/features/emoji/emoji_utils.ts @@ -60,12 +60,14 @@ interface SkinTone { skin_tone?: EmojiSkin; } +type RawEmoji = BaseEmoji & + CustomEmoji & + Pick & + Pick & + SkinTone; + function sanitize( - emoji: BaseEmoji & - CustomEmoji & - Pick & - Pick & - SkinTone, + emoji: RawEmoji, ): | BaseEmoji | (Omit & Pick) { @@ -109,27 +111,17 @@ function sanitize( }; } -function getSanitizedData( - ...args: [ - emoji: BaseEmoji | string, - skin: EmojiSkin | null, - set?: - | 'apple' - | 'google' - | 'twitter' - | 'facebook' - | 'emojione' - | 'messenger', - ] -) { - return sanitize(getData(...args)); -} - -function getData( +type GetDataArgs = [ emoji: BaseEmoji | string, skin: EmojiSkin | null, set?: 'apple' | 'google' | 'twitter' | 'facebook' | 'emojione' | 'messenger', -) { +]; + +function getSanitizedData(...args: GetDataArgs) { + return sanitize(getData(...args)); +} + +function getData(...[emoji, skin, set]: GetDataArgs) { /* eslint-disable @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return */ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ let emojiData: any = {}; @@ -199,11 +191,7 @@ function getData( emojiData.unified = emojiData.variations.shift(); } - return emojiData as BaseEmoji & - CustomEmoji & - Pick & - Pick & - SkinTone; + return emojiData as RawEmoji; /* eslint-enable @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-return */ }