Added TypeScript for frontend

Added type definitions for components, functions, data
Added guards for network responses
fixes #8
This commit is contained in:
2023-07-12 18:59:17 +03:00
parent 8fc85e415f
commit a8b7cfbffa
52 changed files with 1616 additions and 1651 deletions

View File

@ -1,4 +1,12 @@
const categoryGraphics = new Map([
import { isLiteralUnion } from "../utils/types"
const categories = ["PORRIDGE", "conspects", "milk", "bred", "wathing", "cloth",
"fruits_vegatables", "soup", "dinner", "conserves", "pens", "other_things"] as const
type Category = typeof categories[number]
const isCategory = (obj: unknown): obj is Category => isLiteralUnion(obj, categories)
const categoryGraphics = new Map<Category, string>([
["PORRIDGE", "static/PORRIDGE.jpg"],
["conspects", "static/conspects.jpg"],
["milk", "static/milk.jpg"],
@ -14,7 +22,7 @@ const categoryGraphics = new Map([
])
const categoryNames = new Map([
const categoryNames = new Map<Category, string>([
["PORRIDGE", "PORRIDGE"],
["conspects", "Конспекты"],
["milk", "Молочные продукты"],
@ -29,4 +37,5 @@ const categoryNames = new Map([
["other_things", "Всякая всячина"]
])
export { categoryNames, categoryGraphics }
export type { Category }
export { categoryNames, categoryGraphics, isCategory }

View File

@ -1,4 +1,7 @@
const stations = {
const lines = ['red', 'blue', 'green', 'orange', 'violet'] as const
type Lines = typeof lines[number]
const stations: Record<Lines, Set<string>> = {
red: new Set([
"Девяткино",
"Гражданский проспект",
@ -82,7 +85,7 @@ const stations = {
]),
}
const colors = {
const colors: Record<Lines, string> = {
red: "#D6083B",
blue: "#0078C9",
green: "#009A49",
@ -90,7 +93,7 @@ const colors = {
violet: "#702785",
}
const lines = {
const lineNames: Record<Lines, string> = {
red: "Красная",
blue: "Синяя",
green: "Зелёная",
@ -98,4 +101,5 @@ const lines = {
violet: "Фиолетовая",
}
export { stations, colors, lines }
export type { Lines }
export { lines, stations, colors, lineNames }