feat: strict language enum types

This commit is contained in:
DIYgod
2024-06-13 15:50:59 +08:00
parent 810111291c
commit 3fc6ec4531
6 changed files with 43 additions and 7 deletions
@@ -31,6 +31,7 @@ import {
} from "@renderer/components/ui/table"
import { ViewSelectContent } from "@renderer/components/view-select-content"
import { cn } from "@renderer/lib/utils"
import type { SupportedLanguages } from "@renderer/models"
type Operation =
| "contains"
@@ -155,7 +156,10 @@ const FeedOptions = [
},
]
const TransitionOptions = [
const TransitionOptions: {
name: string
value: SupportedLanguages
}[] = [
{
name: "English",
value: "en",
+4 -4
View File
@@ -39,7 +39,7 @@ declare const routes: hono_hono_base.HonoBase<hono.Env, {
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[];
result: {
translation?: string | undefined;
translation?: "en" | "ja" | "zh-CN" | "zh-TW" | undefined;
summary?: boolean | undefined;
rewriteRules?: {
from: string;
@@ -68,7 +68,7 @@ declare const routes: hono_hono_base.HonoBase<hono.Env, {
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[];
result: {
translation?: string | undefined;
translation?: "en" | "ja" | "zh-CN" | "zh-TW" | undefined;
summary?: boolean | undefined;
rewriteRules?: {
from: string;
@@ -440,7 +440,7 @@ declare const routes: hono_hono_base.HonoBase<hono.Env, {
createdAt: string;
} | undefined;
settings?: {
translation?: string | undefined;
translation?: "en" | "ja" | "zh-CN" | "zh-TW" | undefined;
summary?: boolean | undefined;
rewriteRules?: {
from: string;
@@ -502,7 +502,7 @@ declare const routes: hono_hono_base.HonoBase<hono.Env, {
};
read: boolean | null;
settings?: {
translation?: string | undefined;
translation?: "en" | "ja" | "zh-CN" | "zh-TW" | undefined;
summary?: boolean | undefined;
rewriteRules?: {
from: string;
+2
View File
@@ -73,3 +73,5 @@ export type FeedListModel = {
name: string
}[]
}
export type SupportedLanguages = Parameters<typeof apiClient.ai.translation.$get>[0]["query"]["language"]
+3 -2
View File
@@ -1,5 +1,6 @@
import { apiClient } from "@renderer/lib/api-fetch"
import { defineQuery } from "@renderer/lib/defineQuery"
import type { SupportedLanguages } from "@renderer/models"
export const ai = {
translation: ({
@@ -8,7 +9,7 @@ export const ai = {
fields,
}: {
id: string
language?: string
language?: SupportedLanguages
fields: string
}) =>
defineQuery(["translation", id, language], async () => {
@@ -18,7 +19,7 @@ export const ai = {
const res = await apiClient.ai.translation.$get({
query: {
id,
language: language as "en" | "ja" | "zh-CN" | "zh-TW",
language: language as SupportedLanguages,
fields,
},
})