Skip to content

Commit f2fbda7

Browse files
committed
Fix types
1 parent d3a8b7f commit f2fbda7

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

src/services/dictionary-test/dictionary-test.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import * as fs from 'fs'
22

3-
import { Dictionary } from 'services'
3+
import { Dictionary, IBasicData } from 'services'
44

5-
import basicData from './basic.json'
5+
import testData from './basic.json'
66
import { deepDiffMapper } from './deepDiffMapper'
77
import testSnapshot from './snapshot.json'
88

9+
const basicData = testData as IBasicData
10+
11+
912
Dictionary.init(basicData.wordList, basicData.searchIndex)
1013

1114
const snapshot = {}

src/services/dictionary.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ export interface ITranslateResult {
158158
export const ISV_SRC = 'isv-src'
159159
export const ISV = 'isv'
160160

161+
export type WordList = string[][]
162+
export type SearchIndex = Record<string, Array<[string, string[]]>>
163+
161164
class DictionaryClass {
162165
public static getInstance(): DictionaryClass {
163166
if (!DictionaryClass.instance) {
@@ -173,7 +176,7 @@ class DictionaryClass {
173176
private langsList: string[]
174177
private headerIndexes: Map<string, number>
175178
private percentsOfChecked: {[lang: string]: string}
176-
private words: string[][]
179+
private words: WordList
177180
private splittedMap: {[lang: string]: Map<string, string[]>}
178181
private isvSearchLetters: { from: string[], to: string[] }
179182
private isvSearchByWordForms: boolean
@@ -188,9 +191,9 @@ class DictionaryClass {
188191
}
189192

190193
public init(
191-
wordList: string[][],
192-
searchIndex?: any | false,
193-
percentsOfChecked?: any,
194+
wordList: WordList,
195+
searchIndex?: SearchIndex,
196+
percentsOfChecked?: Record<string, string>,
194197
): number {
195198
let startInitTime = 0
196199

@@ -284,7 +287,7 @@ class DictionaryClass {
284287

285288
return initTime
286289
}
287-
public addLang(wordList: string[], searchIndex?: any) {
290+
public addLang(wordList: string[], searchIndex?: SearchIndex) {
288291
const lang = wordList[0]
289292

290293
if (this.hasLang(lang)) {
@@ -303,15 +306,15 @@ class DictionaryClass {
303306
public hasLang(lang): boolean {
304307
return this.headerIndexes.has(lang)
305308
}
306-
public getWordList(): string[][] {
309+
public getWordList(): WordList {
307310
return this.words
308311
}
309312
public getWord(wordId: string) {
310313
if (this.words && this.words.length) {
311314
return this.words.filter((line) => this.getField(line, 'id') === wordId)[0]
312315
}
313316
}
314-
public getIndex() {
317+
public getIndex(): SearchIndex {
315318
const searchIndex = {};
316319

317320
[
@@ -326,7 +329,7 @@ class DictionaryClass {
326329

327330
return searchIndex
328331
}
329-
public translate(translateParams: ITranslateParams, showTime = true): [string[][], number] {
332+
public translate(translateParams: ITranslateParams, showTime = true): [WordList, number] {
330333
const {
331334
inputText,
332335
from,
@@ -517,7 +520,7 @@ class DictionaryClass {
517520
}
518521

519522
public formatTranslate(
520-
results: string[][],
523+
results: WordList,
521524
from: string,
522525
to: string,
523526
flavorisationType: string,

src/services/fetchDictionary.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { addLangs } from 'consts'
22

33
import { isLoadingAction, runSearch } from 'actions'
44

5-
import { Dictionary } from 'services'
5+
import { Dictionary, SearchIndex, WordList } from 'services'
66

77
async function fetchStat() {
88
return fetch('data/translateStatistic.json').then((res) => res.json()).then((data) => data)
@@ -14,7 +14,12 @@ async function fetchLangs(langList: string[]) {
1414
)
1515
}
1616

17-
async function fetchBasic() {
17+
export interface IBasicData {
18+
wordList: WordList,
19+
searchIndex?: SearchIndex,
20+
}
21+
22+
async function fetchBasic(): Promise<IBasicData> {
1823
return await fetch('data/basic.json').then((res) => res.json())
1924
}
2025

0 commit comments

Comments
 (0)