Skip to content

Commit

Permalink
DoesWordExistErrorTypes enum removed
Browse files Browse the repository at this point in the history
  • Loading branch information
Deykun committed May 14, 2024
1 parent d416713 commit 7689b7e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
18 changes: 11 additions & 7 deletions src/api/getDoesWordExist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ type FetchedWordsListByKeys = {
[key: string]: string[]
};

export enum DoesWordExistErrorType {
TooShort = 'too_short',
Fetch = 'fetch',
}
export const DoesWordExistErrorTypes = {
TooShort: 'too_short',
Fetch: 'fetch',
} as const;

export type ValueOf<T> = T[keyof T];

type DoesWordExistErrorType = typeof DoesWordExistErrorTypes[keyof typeof DoesWordExistErrorTypes];

type GetDoesWordExistReport = {
doesWordExist: boolean,
isError: boolean,
errorType?: DoesWordExistErrorType,
errorType?: DoesWordExistErrorType
};

const cachedKeys: FetchedWordsListByKeys = {};
Expand All @@ -26,7 +30,7 @@ export const getDoesWordExist = async (word: string, lang: string): Promise<GetD
return {
doesWordExist: false,
isError: true,
errorType: DoesWordExistErrorType.TooShort,
errorType: DoesWordExistErrorTypes.TooShort,
};
}

Expand Down Expand Up @@ -54,7 +58,7 @@ export const getDoesWordExist = async (word: string, lang: string): Promise<GetD
return {
doesWordExist: false,
isError: true,
errorType: DoesWordExistErrorType.Fetch,
errorType: DoesWordExistErrorTypes.Fetch,
};
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/api/getWordReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Affix, AffixStatus, UsedLetters } from '@common-types';

import { SUBMIT_ERRORS } from '@const';

import getDoesWordExist, { DoesWordExistErrorType } from '@api/getDoesWordExist';
import getDoesWordExist, { DoesWordExistErrorTypes } from '@api/getDoesWordExist';
import compareWords from '@api/utils/compareWords';

import { mergeLettersData } from '@utils/statistics';
Expand Down Expand Up @@ -101,7 +101,7 @@ export const getWordReport = async (
const doesWordExistReport = await getDoesWordExist(wordToSubmit, lang);

if (doesWordExistReport.isError) {
if (doesWordExistReport.errorType === DoesWordExistErrorType.Fetch) {
if (doesWordExistReport.errorType === DoesWordExistErrorTypes.Fetch) {
return {
isError: true, word: wordToSubmit, isWon: false, type: SUBMIT_ERRORS.WORD_FETCH_ERROR,
};
Expand Down

0 comments on commit 7689b7e

Please sign in to comment.