Skip to content

Commit

Permalink
fixed getTranslatedData types (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOnlyTails authored Feb 18, 2024
1 parent 96e1b10 commit eda3262
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions schemas/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ export type LocalizedSignParameters = ParametersTranslation[string];
export type FontLinks = Font["links"];

export function getTranslatedData<
L extends object,
K extends keyof L,
T extends { translations: { en: L } & Record<string, L> },
>(data: T, key: K, language: string): L[K] {
return (data.translations[language] ?? data.translations["en"])[key];
Obj extends { translations: Record<string, object> },
Key extends keyof Obj["translations"][string],
>(data: Obj, key: Key, language: string): Obj["translations"][string][Key] {
return ((data.translations[language] ?? data.translations["en"]!) as Obj["translations"][string])[
key
];
}

0 comments on commit eda3262

Please sign in to comment.