From d922b619e31dfe8625f94b7cfb0741836030ee48 Mon Sep 17 00:00:00 2001 From: taichi221228 Date: Thu, 2 May 2024 13:37:22 +0900 Subject: [PATCH] Refactor `uniq` function for TS compliance and efficiency improvements This commit refactors the `uniq` function found in the emoji utilities to accept an explicitly defined array as an argument, improving overall TypeScript compliance. It also replaces the `.indexOf` method with the more efficient `.includes` method for better performance. --- app/javascript/mastodon/features/emoji/emoji_utils.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/app/javascript/mastodon/features/emoji/emoji_utils.ts b/app/javascript/mastodon/features/emoji/emoji_utils.ts index 2c56ad76fe..4174531835 100644 --- a/app/javascript/mastodon/features/emoji/emoji_utils.ts +++ b/app/javascript/mastodon/features/emoji/emoji_utils.ts @@ -200,25 +200,22 @@ function getData(...[emoji, skin, set]: GetDataArgs) { /* 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 */ } -/* eslint-disable */ - -// @ts-expect-error -function uniq(arr) { - // @ts-expect-error +function uniq(arr: []) { return arr.reduce((acc, item) => { - if (acc.indexOf(item) === -1) { + if (!acc.includes(item)) { acc.push(item); } return acc; }, []); } +/* eslint-disable */ + // @ts-expect-error function intersect(a, b) { const uniqA = uniq(a); const uniqB = uniq(b); - // @ts-expect-error return uniqA.filter((item) => uniqB.indexOf(item) >= 0); }