convert type to union

environments/review-gleasonato-trtlxz/deployments/525^2
ewwwwwwww 2022-07-04 20:59:39 -07:00
rodzic 8d8cf53ac4
commit bd9a33201a
3 zmienionych plików z 11 dodań i 10 usunięć

Wyświetl plik

@ -20,7 +20,7 @@ const AutosuggestEmoji: React.FC<IAutosuggestEmoji> = ({ emoji }) => {
if (isCustomEmoji(emoji)) {
url = emoji.imageUrl;
alt = emoji.colons;
} else if (isNativeEmoji(emoji)) {
} else {
const mapping = unicodeMapping[emoji.native] || unicodeMapping[emoji.native.replace(/\uFE0F$/, '')];
if (!mapping) {
@ -29,8 +29,6 @@ const AutosuggestEmoji: React.FC<IAutosuggestEmoji> = ({ emoji }) => {
url = joinPublicPath(`packs/emoji/${mapping.unified}.svg`);
alt = emoji.native;
} else {
return <div />
}
return (

Wyświetl plik

@ -21,22 +21,23 @@ import type { Emoji as EmojiMart, CustomEmoji as EmojiMartCustom } from 'emoji-m
* and one type that is used everywhere that the above two are converted into
*/
export interface Emoji {
export interface CustomEmoji {
id: string,
colons: string,
custom?: boolean,
}
export interface CustomEmoji extends Emoji {
custom: true,
imageUrl: string,
}
export interface NativeEmoji extends Emoji {
export interface NativeEmoji {
id: string,
colons: string,
custom?: boolean,
unified: string,
native: string,
}
export type Emoji = CustomEmoji | NativeEmoji;
export function isCustomEmoji(emoji: Emoji): emoji is CustomEmoji {
return (emoji as CustomEmoji).imageUrl !== undefined;
}

Wyświetl plik

@ -2,6 +2,8 @@ import { Index } from 'flexsearch';
import data from './data';
import { Emoji as EmojiType } from './index';
import type { Emoji, CustomEmoji } from 'emoji-mart';
const index = new Index({
@ -25,7 +27,7 @@ export const addCustomToPool = (customEmojis: Emoji<CustomEmoji>[]) => {
}
};
const search = (str: string, options: searchOptions, custom_emojis: any) => {
const search = (str: string, options: searchOptions, custom_emojis: any): EmojiType[] => {
return index.search(str, options.maxResults)
.flatMap(id => {
if (Number.isInteger(id)) {