diff --git a/src/background/database.ts b/src/background/database.ts index 3b76b20..6318f6a 100644 --- a/src/background/database.ts +++ b/src/background/database.ts @@ -1,11 +1,3 @@ -export interface flashcard { - id?: IDBValidKey; - src: string; - result: string; - dateAdded: Date; - exported: boolean; -} - export class Flashcards { db: IDBDatabase; @@ -26,8 +18,8 @@ export class Flashcards { }; } - addTranslation(t: Translation | flashcard): Promise { - let card: flashcard; + addTranslation(t: Translation | Flashcard): Promise { + let card: Flashcard; if ("dateAdded" in t && "exported" in t) card = t; else { card = { @@ -50,7 +42,7 @@ export class Flashcards { }); } - async getAllCards(): Promise> { + async getAllCards(): Promise> { let req = this.db .transaction(["flashcards"], "readonly") .objectStore("flashcards") diff --git a/src/communication.ts b/src/communication.ts index 97e67e7..9cf2cad 100644 --- a/src/communication.ts +++ b/src/communication.ts @@ -1,6 +1,5 @@ //There has to be a better way to do this while remaining type safe... import { browser, Runtime } from "webextension-polyfill-ts"; -import { flashcard } from "./background/database"; export class Communicator { setEnabledCallback: (value: boolean, sender: Runtime.MessageSender) => void; @@ -11,9 +10,9 @@ export class Communicator { ) => Promise; addFlashcardCallback: ( - value: Translation | flashcard, + value: Translation | Flashcard, sender: Runtime.MessageSender - ) => Promise; + ) => Promise; constructor() { browser.runtime.onMessage.addListener( @@ -41,7 +40,7 @@ export class Communicator { commandKind: commandKinds.translate, toTranslate: toTranslate, }); - static addFlashcard = (card: flashcard | Translation) => { + static addFlashcard = (card: Flashcard | Translation) => { sendMessage({ commandKind: commandKinds.addFlashcard, card: card }); }; } @@ -70,7 +69,7 @@ interface translate { interface addFlashcard { commandKind: commandKinds.addFlashcard; - card: Translation | flashcard; + card: Translation | Flashcard; } export type command = setEnabled | getEnabled | translate | addFlashcard; diff --git a/src/frontend/content_script/content_script.ts b/src/frontend/content_script/content_script.ts index 2ce7bfa..299bce5 100644 --- a/src/frontend/content_script/content_script.ts +++ b/src/frontend/content_script/content_script.ts @@ -1,5 +1,5 @@ import "./custom_elements"; -import Communicator from "../../communication"; +import { Communicator } from "../../communication"; import tippy from "tippy.js"; import "tippy.js/dist/tippy.css"; import "./tippy.scss"; diff --git a/src/types.d.ts b/src/types.d.ts index 46b749a..ee91d73 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -3,8 +3,15 @@ declare module "*?raw" { export = contents; } -type TranslationRequest = string; -interface Translation { +declare interface Translation { src: string; result: string; } + +declare interface Flashcard { + id?: IDBValidKey; + src: string; + result: string; + dateAdded: Date; + exported: boolean; +}